1

I have nginx running as a reverse proxy for a nextcloud server hosted on apache on a different virtual machine. I'd like to be able to access it via cloud.example.com. With my current rules I have to put in cloud.example.com/nextcloud. I have googled, searched, and the closest I got was being able to go to cloud.example.com and it would redirect to cloud.example.com/nextcloud, but I'd like to keep the /nextcloud out of the address bar if possible. Do I need to have a /nextcloud location that does the proxy pass in addition to the /?

This is my current nginx.conf:

server {
    listen       443 ssl http2 default_server;
    server_name  _;
    ssl_certificate /etc/letsencrypt/live/cloud.domain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/cloud.domain.com/privkey.pem;
    ssl_stapling on;
    ssl_stapling_verify on;

    location /.well-known {
        alias /var/www/.well-known;
    }
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-By $server_addr:$server_port;
        proxy_set_header Host $http_host;
        proxy_pass http://10.37.70.6:8080;
    }

}
4
  • You'll need to correct the empty server_name, and yes you'll need another location. You need to read the Nginx documentation or a tutorial.
    – Tim
    Feb 4, 2017 at 18:28
  • I'm currently only proxying one site, and only one domain routes here, so would that have to change? Would I do a re-write on location / to add /nextcloud and then have a /nextcloud location that basically does what / does now? I've read a bunch of documentation and examples, and I can while I can get redirects to work, I can't get the /nextcloud to stay out of the address bar.
    – Ryan
    Feb 4, 2017 at 18:42
  • You'd get away with your server_name as is, but better practice to set it properly. You don't need to change your root location, you just need to add the second location. Read the documentation again, this is the basics of Nginx.
    – Tim
    Feb 4, 2017 at 19:24
  • I would just get rid of Apache and serve Nextcloud with nginx...in fact I've already done just this. It works perfectly well. Feb 4, 2017 at 19:59

2 Answers 2

0

keeping /nextcloud out of the address bar would require the use of if statements which are apparently evil.

The problem is that you would need to evaluate whether the http request contains /nextcloud at the start, since this will change your proxy request because the apache server requires /nextcloud to be in the url. Also if you truly want this removed from the address bar, you would also have to inspect responses since the apache server will include links that contain the /nextcloud.

Seems like your best bet would be either to reconfigure the apache server to not need the /nextcloud, or just simply tell nginx to redirect / to /nextcloud as you already figured out. This is simple to the user since he/she only needs to remember the domain cloud.domain.com

0

The problem here is not the configuration. The problem is the content which the backend apache server is providing. Links and resource references contain the /nextcloud/ path. This needs to be replaced before presenting the content to the user/client. This is not always a reliable solution:

    location / {
            sub_filter '/nextcloud/' '/';
            sub_filter_once off;

            proxy_pass http://10.37.70.6:8080/nextcloud/;
    }
    location /nextcloud/ {
            rewrite ^/nextcloud(/.*)$ $1 redirect;
    }

This requires the ngx_http_sub_module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.