Nginx配置二级域名

2019-03-26  本文已影响0人  一双鞋两双

一、找到系统Nginx的配置文件

 find / -name nginx.conf

我的电脑是在:/etc/nginx/nginx.conf

nginx.conf

二、在/etc/nginx目录的conf.d文件夹创建一个default.conf文件

conf.d

    解释:因为在nginx.conf文件的最后面有这么一段代码:include /etc/nginx/conf.d/*.conf; 引入conf.d下所有的.conf文件。

三、在conf.d/default.conf文件内添加一下内容:

server {

    listen      80;

    server_name  celue.bgsm888.com;        // ------(需要更改) 监听的域名

    #charset koi8-r;

#access_log  logs/host.access.log  main;

    location / {

        root  /home/www/celue;                        // ---------(需要更改) 项目地址

        index  index.php index.html index.htm;

  # example

#ModSecurityEnabled on;

#ModSecurityConfig /etc/nginx/modsecurity.conf;

    }

    error_page  404              /404.html;

    location = /404.html {

        root  /usr/share/nginx/html;

    }

location ~* \.(eot|otf|ttf|woff|svg)$ {

        root /home/www/celue;                                 // ---------(需要更改) 项目地址

  add_header  Access-Control-Allow-Origin *;

}

    # redirect server error pages to the static page /50x.html

#

    error_page  500 502 503 504  /50x.html;

    location = /50x.html {

        root  /usr/share/nginx/html;

    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ \.php$ {

#    proxy_pass  http://127.0.0.1;

#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

    location ~ \.php {

        root          /home/www/celue;                                                 // ---------(需要更改) 项目地址

  fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

        fastcgi_index  index.php;

        fastcgi_split_path_info ^(.+\.php)(/?.+)$;

        fastcgi_param PATH_INFO $fastcgi_path_info;

        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

        include        fastcgi_params;

        fastcgi_pass  127.0.0.1:9000;

        fastcgi_connect_timeout 600;

      fastcgi_send_timeout 600;

      fastcgi_read_timeout 600;

      fastcgi_buffer_size 256k;

      fastcgi_buffers 16 256k;

      fastcgi_busy_buffers_size 512k;

      fastcgi_temp_file_write_size 512k;

    }

    # deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

#location ~ /\.ht {

#    deny  all;

#}

}

四、重启nginx(查询自己的sbin/nginx目录替换)

/usr/local/nginx/sbin/nginx -t

/usr/local/nginx/sbin/nginx -s reload

五、遇到的问题

    在配置完成之后,访问出现了403。

    5.1 首先看看是否有index文件

    检查后发现都有,应该不是这个原因。

    5.2 再检查是否是文件夹的权限问题

chmod -R 777

    使用上面的命令后还是不行。

    5.3 检查启动用户和nginx工作用户是否一致

    修改nginx.conf的第一行,改成下面这样

user  root;

    重启nginx,访问正常。

参考地址:1、CSDN使用nginx配置二级域名

                 2、Nginx配置文件详细说明

上一篇 下一篇

猜你喜欢

热点阅读