问题:Nginx不根据我在单独的配置文件中定义的规则路由通信,只显示默认的404响应。
上下文:我有一个用Go编写的小型中间件应用程序,它为GET请求提供了一个简单的响应。应用程序部署在端口8080上:
$ curl localhost:8080
ok我希望编写一个Nginx配置,允许我将调用从/api路由到localhost:8080,这将允许我执行以下操作
$ curl localhost/api
ok为此,我编写了以下配置:
/etc/nginx/sites-available/custom-nginx-rules
server {
listen 80;
location /api {
proxy_pass http://localhost:8080;
}
}我还为上面的文件在/etc/nginx/site中创建了一个启用/的软链接。
$ ls -l /etc/nginx/sites-enabled
total 0
lrwxrwxrwx 1 root root 34 Jan 19 16:42 default -> /etc/nginx/sites-available/default
lrwxrwxrwx 1 root root 32 Feb 20 14:56 custom-nginx-rules -> /etc/nginx/sites-available/custom-nginx-rules其余的设置是香草Nginx,什么都没有改变。尽管设置很简单,但在进行以下调用时,我将得到一个404:
$ curl localhost/api
404 Not Found
404 Not Found
nginx/1.10.3Other信息:下面是安装在我的系统上的nginx包(运行在raspberry pi上)
$ dpkg -l | grep nginx
ii libnginx-mod-http-auth-pam 1.10.3-1+deb9u1 armhf PAM authentication module for Nginx
ii libnginx-mod-http-dav-ext 1.10.3-1+deb9u1 armhf WebDAV missing commands support for Nginx
ii libnginx-mod-http-echo 1.10.3-1+deb9u1 armhf Bring echo and more shell style goodies to Nginx
ii libnginx-mod-http-geoip 1.10.3-1+deb9u1 armhf GeoIP HTTP module for Nginx
ii libnginx-mod-http-image-filter 1.10.3-1+deb9u1 armhf HTTP image filter module for Nginx
ii libnginx-mod-http-subs-filter 1.10.3-1+deb9u1 armhf Substitution filter module for Nginx
ii libnginx-mod-http-upstream-fair 1.10.3-1+deb9u1 armhf Nginx Upstream Fair Proxy Load Balancer
ii libnginx-mod-http-xslt-filter 1.10.3-1+deb9u1 armhf XSLT Transformation module for Nginx
ii libnginx-mod-mail 1.10.3-1+deb9u1 armhf Mail module for Nginx
ii libnginx-mod-stream 1.10.3-1+deb9u1 armhf Stream module for Nginx
ii nginx 1.10.3-1+deb9u1 all small, powerful, scalable web/proxy server
ii nginx-common 1.10.3-1+deb9u1 all small, powerful, scalable web/proxy server - common files
ii nginx-full 1.10.3-1+deb9u1 armhf nginx web/proxy server (standard version)我还要求此设置独立于任何主机或服务器名称。不管主机是什么,它都应该执行路由。
运行nginx -T命令确认文件已加载。错误日志也是空的。
发布于 2018-02-21 12:34:24
从default中删除符号链接/etc/nginx/sites-enabled并重新启动nginx。
否则,此default配置用于在custom-nginx-rules之前为请求提供服务
https://serverfault.com/questions/898149
复制相似问题