首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Nginx没有按照我的定制规则进行路由

Nginx没有按照我的定制规则进行路由
EN

Server Fault用户
提问于 2018-02-21 07:27:25
回答 1查看 234关注 0票数 0

问题:Nginx不根据我在单独的配置文件中定义的规则路由通信,只显示默认的404响应。

上下文:我有一个用Go编写的小型中间件应用程序,它为GET请求提供了一个简单的响应。应用程序部署在端口8080上:

代码语言:javascript
运行
复制
$ curl localhost:8080
ok

我希望编写一个Nginx配置,允许我将调用从/api路由到localhost:8080,这将允许我执行以下操作

代码语言:javascript
运行
复制
$ curl localhost/api
ok

为此,我编写了以下配置:

/etc/nginx/sites-available/custom-nginx-rules

代码语言:javascript
运行
复制
server {
    listen 80;

    location /api {
        proxy_pass http://localhost:8080;
    }
}

我还为上面的文件在/etc/nginx/site中创建了一个启用/的软链接。

代码语言:javascript
运行
复制
$ 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:

代码语言:javascript
运行
复制
$ curl localhost/api

404 Not Found

404 Not Found
nginx/1.10.3

Other信息:下面是安装在我的系统上的nginx包(运行在raspberry pi上)

代码语言:javascript
运行
复制
$ 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命令确认文件已加载。错误日志也是空的。

EN

回答 1

Server Fault用户

发布于 2018-02-21 12:34:24

default中删除符号链接/etc/nginx/sites-enabled并重新启动nginx。

否则,此default配置用于在custom-nginx-rules之前为请求提供服务

票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/898149

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档