简体   繁体   English

nginx反向代理-仅适用于/

[英]nginx reverse proxy - only works on /

On my NAS I'm running seafile as an alternative to dropbox/owncloud. 在我的NAS上,我正在运行seafile来替代dropbox / owncloud。 I'm using nginx and reverse proxy to serve the webgui using/forcing SSL. 我正在使用nginx和反向代理使用/强制使用SSL来提供webgui。 Everything for this works fine. 一切正常。

Now, I want to set up some other locations for other things running on the NAS (couch potato, plex etc). 现在,我想为NAS上运行的其他东西(沙发土豆,plex等)设置其他位置。 This is the relevant part of my nginx.conf file: 这是我的nginx.conf文件的相关部分:

server {
    listen 80;
    server_name domain.net, 192.168.1.50;

rewrite ^ https://$http_host$request_uri? permanent;    # force redirect http to https

}



server {
        listen 443;
        ssl on;
        ssl_certificate C:/nginx-1.6.3/conf/ssl/ssl-bundle.crt;        # path to your ssl certificate
        ssl_certificate_key C:/nginx-1.6.3/conf/ssl/server.key;    # path to your private key

        server_name domain.net, 192.168.1.50;

        proxy_set_header X-Forwarded-For $remote_addr;

        add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";
        server_tokens off;

    location /couchpotato {
        proxy_pass http://127.0.0.1:5050;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

        location /cloud {
            fastcgi_pass    127.0.0.1:8000;
            fastcgi_param   SCRIPT_FILENAME     $document_root$fastcgi_script_name;
            fastcgi_param   PATH_INFO           $fastcgi_script_name;

            fastcgi_param   SERVER_PROTOCOL        $server_protocol;
            fastcgi_param   QUERY_STRING        $query_string;
            fastcgi_param   REQUEST_METHOD      $request_method;
            fastcgi_param   CONTENT_TYPE        $content_type;
            fastcgi_param   CONTENT_LENGTH      $content_length;
            fastcgi_param   SERVER_ADDR         $server_addr;
            fastcgi_param   SERVER_PORT         $server_port;
            fastcgi_param   SERVER_NAME         $server_name;
            fastcgi_param   HTTPS               on;
            fastcgi_param   HTTP_SCHEME         https;

            access_log      logs/seahub.access.log;
            error_log       logs/seahub.error.log;
        }

        location /seafhttp {
            rewrite ^/seafhttp(.*)$ $1 break;
            proxy_pass http://127.0.0.1:8082;
            client_max_body_size 0;
            proxy_connect_timeout  36000s;
            proxy_read_timeout  36000s;
        }

    location /seafmedia {
            rewrite ^/seafmedia(.*)$ /media$1 break;
            root C:/Seafile/seafile-server-4.0.6/seahub;
        }

        location /media {
            root C:/Seafile/seafile-server-4.0.6/seahub;
        }

    }

visiting domain.net/cloud (or 192.168.1.50/cloud) gets me to seafile without a problem. 访问domain.net/cloud(或192.168.1.50/cloud)可以毫无问题地访问seafile。 visiting domain.net gives me the default nginx page, which makes sense as no location is defined for that 访问domain.net给了我默认的nginx页面,这很有意义,因为没有为该位置定义位置

the problem is going to domain.net/couchpotato takes me to https://domain.net/#couchpotato and it doesnt load 问题出在domain.net/couchpotato,带我到https://domain.net/#couchpotato ,它没有加载

if in the nginx.conf file I change location /couchpotato {} to location / {} then couchpotato will load correctly 如果在nginx.conf文件中,我将location /couchpotato {}更改为location / {}那么oucherpotato将正确加载

Im pretty sure theres something wrong in the way I've configured nginx but Im not sure what that is as this is my first time using it 我很确定我配置nginx的方式有问题,但是我不确定那是什么,因为这是我第一次使用它

So my question is, why is it that using /couchpotato as a location does not work? 所以我的问题是,为什么将/ couchpotato用作位置不起作用? But using / does? 但是使用/呢?

I don't know anything about couchpotato, but my guess is that it is not configured to be served from a "subdirectory". 我对Couchpotato一无所知,但我猜测它没有配置为从“子目录”提供。 When you try to access it from domain.net/couchpotato the URI passed to it is /couchpotato, and I assume that it doesn't know how to handle that. 当您尝试从domain.net/couchpotato访问它时,传递给它的URI是/ couchpotato,我认为它不知道如何处理。

Try one of these things: 尝试以下方法之一:

1) Configure couchpotato to serve from /couchpotato (this is done in the actual webapp somewhere). 1)将Couchpotato配置为从/ couchpotato提供服务(这是在实际的Web应用程序中完成的)。 Wordpress for example calls this the "Site URL" and it's configurable in the admin panel. 例如,WordPress将其称为“站点URL”,并且可以在管理面板中对其进行配置。

2) Add a rewrite like you have for seafhttp. 2)像添加seafhttp一样添加重写。

rewrite ^/couchpotato(.*)$ $1 break;

This will remove the /couchpotato from the URL for internal processing and will pass the expected URI to the webapp. 这将从URL中删除/ couchpotato进行内部处理,并将预期的URI传递到webapp。

Hope this helps. 希望这可以帮助。

我最终将seafile更改为使用根域(可通过/访问),然后设置其他位置(如/ couchpotato)可以正常工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM