nginx访问本地目录一直不好使_nginx 配置根目录不生效问题

无论如何配置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/*注释掉。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值