nginx 反向代理 - 仅适用于 /

nginx reverse proxy - only works on /

在我的 NAS 上,我使用 运行 seafile 作为 dropbox/owncloud 的替代品。我正在使用 nginx 和反向代理服务 webgui using/forcing SSL。一切正常。

现在,我想在 NAS(沙发土豆、plex 等)上为其他东西 运行 设置一些其他位置。这是我的 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(.*)$  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 break;
            root C:/Seafile/seafile-server-4.0.6/seahub;
        }

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

    }

访问域。net/cloud(或 192.168.1.50/cloud)让我毫无问题地访问 Seafile。访问 domain.net 给了我默认的 nginx 页面,这是有道理的,因为没有为那个

定义位置

问题出在域上。net/couchpotato 带我到 https://domain.net/#couchpotato 但它没有加载

如果我在 nginx.conf 文件中将 location /couchpotato {} 更改为 location / {} 那么 couchpotato 将正确加载

我很确定我配置 nginx 的方式有问题,但我不确定那是什么,因为这是我第一次使用它

所以我的问题是,为什么使用 /couchpotato 作为位置不起作用?但是使用 / 呢?

我对 couchpotato 一无所知,但我猜它没有配置为从 "subdirectory" 提供服务。当您尝试从域访问它时。net/couchpotato 传递给它的 URI 是 /couchpotato,我认为它不知道如何处理它。

尝试以下方法之一:

1) 配置 couchpotato 以从 /couchpotato 提供服务(这是在实际的 webapp 某处完成的)。例如,Wordpress 将其称为 "Site URL" 并且可以在管理面板中进行配置。

2) 像对 seafhttp 一样添加重写。

rewrite ^/couchpotato(.*)$  break;

这将从 URL 中删除 /couchpotato 以进行内部处理,并将预期的 URI 传递给 webapp。

希望对您有所帮助。

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