Simon
Simon

Reputation: 10158

nginx reverse proxy - only works on /

On my NAS I'm running seafile as an alternative to dropbox/owncloud. I'm using nginx and reverse proxy to serve the webgui using/forcing SSL. 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). This is the relevant part of my nginx.conf file:

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. visiting domain.net gives me the default nginx page, which makes sense as no location is defined for that

the problem is going to domain.net/couchpotato takes me to https://domain.net/#couchpotato and it doesnt load

if in the nginx.conf file I change location /couchpotato {} to location / {} then couchpotato will load correctly

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

So my question is, why is it that using /couchpotato as a location does not work? But using / does?

Upvotes: 0

Views: 1409

Answers (2)

Simon
Simon

Reputation: 10158

I ended up changing seafile to use a root domain (accessible at /), after which setting up other locations like /couchpotato work fine

Upvotes: 0

Andrew Grasso
Andrew Grasso

Reputation: 156

I don't know anything about couchpotato, but my guess is that it is not configured to be served from a "subdirectory". 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.

Try one of these things:

1) Configure couchpotato to serve from /couchpotato (this is done in the actual webapp somewhere). Wordpress for example calls this the "Site URL" and it's configurable in the admin panel.

2) Add a rewrite like you have for 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.

Hope this helps.

Upvotes: 1

Related Questions