900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > nginx访问本地目录一直不好使_nginx 配置根目录不生效问题

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

时间:2023-02-20 06:25:52

相关推荐

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/*注释掉。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。