您的位置:首页 > 运维架构 > Nginx

nginx多站点配置问题

2017-09-04 14:35 239 查看

在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为什么无法请求成功的问题
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx