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

nginx 配置根目录不生效问题

2018-02-06 09:35 2151 查看
无论如何配置ngnix.conf,还是配置/etc/nginx/conf.d/xxxx.conf 文件的配置,都无法实现proxy_pass功能!

为啥……?

原来新版本的nginx的ngnix.conf文件增加了一行:

include /etc/nginx/sites-enabled/*

而这个目录底下有一个default文件,这个文件定义了:

server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}


由于该include指令在nginx.conf文件中是最后一个,所以,前面配置的

server{
listen 80;
location / {
# 所有你的配置都不会生效,会被后面的缺省配置覆盖掉!!
proxy_pass http://localhost:8080/ }
}


如此一来,如果需要配置80的代理,你不能在ngnix 文件,或者conf.d目录下,而应该替换/etc/nginx/sites-enabled/default文件中的配置。

或者把include /etc/nginx/sites-enabled/*注释掉。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx