首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >nginx:没有这样的资源

nginx:没有这样的资源
EN

Stack Overflow用户
提问于 2015-11-22 07:35:27
回答 1查看 3.8K关注 0票数 2

我试图代理转发一个运行在端口8002的/客户端到一个位置/deluge,并让位置web的其余部分为一个目录提供服务。

代码语言:javascript
复制
upstream deluge {
        server 127.0.0.1:8002;
}

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        index index.html index.htm;
        server_name localhost;

        location / {
                root /home/ubuntu/web;
                autoindex on;
                try_files $uri $uri/ =404;
        }

        location /deluge {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://deluge;
        }
}

我验证了deluge-web是否正在运行:

代码语言:javascript
复制
root:~# ps -aux | grep deluge
root      7652  0.0  0.2  67896  2200 pts/0    S    23:20   0:00 sudo nohup deluge-web -p 8002
root      7653  0.0  2.2  72488 22832 pts/0    S    23:20   0:00 /usr/bin/python /usr/bin/deluge-web -p 8002
root      7743  0.0  0.0  10464   936 pts/0    S+   23:31   0:00 grep --color=auto deluge

访问http://xx.xx.xx.xx/运行得很好。但是访问http://xx.xx.xx.xx/deluge会抛出一个404错误:

代码语言:javascript
复制
No Such Resource

No such child resource.
EN

回答 1

Stack Overflow用户

发布于 2016-03-13 18:32:14

我想这就是答案!

Correct proxy path in nginx.conf

你需要在location和proxy_pass的末尾加上斜杠,这样它就不会重定向位置了。

代码语言:javascript
复制
pasted from answer-

    location /test/ {
      proxy_pass http://localserver.com/;
    }

nginx does NOT replace URI path part if the proxy_pass directive does not have a URI path itself. So my fix of adding a slash (slash is treated as a URI path) at the end triggers the URI path replacement.

Reference: http://wiki.nginx.org/HttpProxyModule#proxy_pass

If it is necessary to transmit URI in the unprocessed form then directive >proxy_pass should be used without URI part
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33849915

复制
相关文章

相似问题

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