ssl - nginx 反向代理 - 仅适用于/

标签 ssl nginx reverse-proxy couchpotato

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

现在,我想为 NAS 上运行的其他东西(沙发土 bean 、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(.*)$ $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;
        }

    }

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

问题是去 domain.net/couchpotato 带我到 https://domain.net/#couchpotato而且它不加载

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

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

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

最佳答案

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

尝试以下其中一项:

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

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

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

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

希望这对您有所帮助。

关于ssl - nginx 反向代理 - 仅适用于/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29724594/

相关文章:

Django url 在 nginx 代理后面带有 https

linux - Nginx 返回 499

python - 反向代理: Flask app with Bokeh server on Nginx

java - Android Studio HTTPS 和 SSL 证书

java - MQQueueManager.<init> 为指定的 MQEnvironment.sslCipherSuite 引发 MQJE001 : Completion Code '2' , 原因 '2400'

django - 502 错误网关与 NGINX、Gunicorn、Django

wordpress - 更改 url 结构后 nginx 301 重定向

apache - Centos 6 上的 Apache 反向代理

ruby-on-rails - 将反向代理添加到heroku

php - http 调用 https/SSL 网络服务,安全吗?