nginx多站点配置问题

来源:互联网 发布:西安java程序员薪酬 编辑:程序博客网 时间:2024/05/17 02:42

在nginx的conf文件夹中创建一个vhost的文件夹

每个站点都可以配置一个conf的配置文件
文件内容具体如下

server{    listen 80;    server_name xxx.example.com;    root /data/www/xxx;   //网页页面的位置地址    index index.php index.html index.htm;    location /api/ {        proxy_set_header Host $host;        proxy_set_header Host $host;        proxy_set_header X-Real-Ip $remote_addr;        proxy_set_header X-Forwarded-For $remote_addr;                   proxy_pass http://simlergray.cn:8080;    //配置反向代理    }}

nginx.conf 配置

user nobody;worker_processes auto;error_log /var/log/nginx/error.log;pid /run/nginx.pid;events {    worker_connections 1024;}http {    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '                      '$status $body_bytes_sent "$http_referer" '                      '"$http_user_agent" "$http_x_forwarded_for"';    access_log  /var/log/nginx/access.log  main;    sendfile            on;    tcp_nopush          on;    tcp_nodelay         on;    keepalive_timeout   65;    types_hash_max_size 2048;    client_max_body_size 6M;    client_body_buffer_size 128K;    include             /etc/nginx/mime.types;    default_type        application/octet-stream;    # Load modular configuration files from the /etc/nginx/conf.d directory.    # See http://nginx.org/en/docs/ngx_core_module.html#include    # for more information.    #include /etc/nginx/conf.d/*.conf; #   server {        #listen       80 default_server;        #listen       [::]:80 default_server;        #server_name  _;        #root         /usr/share/nginx/html;        # Load configuration files for the default server block.        #include /etc/nginx/default.d/*.conf;#   listen 80;    #    server_name localhost;   #     location / {  #             root  /data/www/index; #           index index.html index.htm;#    }        #error_page 404 /404.html;        #    location = /40x.html {        #}        #error_page 500 502 503 504 /50x.html;        #    location = /50x.html {        #}   # }   include vhost/*.conf;}

配置完之后 还有最后一步,就是配置域名的解析,每一个二级域名都去绑定本服务器的ip地址,这是很重要的一个步骤,新手很容易忘记这一步,或者不知道这一步,很容易出现明明配置好了 nginx为什么无法请求成功的问题

原创粉丝点击