Reverse proxy issue with Nginx, showing 404 error

I’m running nextcloud 12 on apache at port 8888 with nginx as reverse proxy, the below configuration is giving 404 when i hit nextcloud from outside via nginx, but it working fine on internal network hosted on apache.

below are the configuration details.

pi@raspberrypi:~ $ nginx -v
nginx version: nginx/1.10.3
pi@raspberrypi:~ $ apache2 -v
Server version: Apache/2.4.25 (Raspbian)
Server built:   2017-09-19T18:58:57
pi@raspberrypi:~ $ php -v
PHP 7.0.27-0+deb9u1 (cli) (built: Jan  5 2018 13:51:52) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.27-0+deb9u1, Copyright (c) 1999-2017, by Zend Technologies
pi@raspberrypi:~ $

Internal URL (directly hits apache) : http://192.168.1.254:8888/nextcloud/
Outside URL (via nginx reverse proxy) : https://cloud.domain.com

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Not Found
The requested URL /nextcloud/nextcloud/index.php/login was not found on this server.

Apache/2.4.25 (Raspbian) Server at cloud.domain.com Port 80

++++++++++++++++++++++++++++++++++++++++++++++++++++++++

pi@raspberrypi:~ $ sudo cat /var/www/html/nextcloud/config/config.php 
<?php
$CONFIG = array (
  'instanceid' => 'oc0okf3ebww7',
  'passwordsalt' => '@@@@@@@@@@',
  'secret' => '@@@@@@@@@@@@@@@@@@@@@@@',
  'trusted_domains' => 
  array (
    0 => '192.168.1.254:8888',
    1 => 'cloud.domain.com',
    2 => 'cloud.domain.com:8888',
  ),
  'datadirectory' => '/var/www/html/nextcloud/data',
  'overwrite.cli.url' => 'http://192.168.1.254:8888/nextcloud',
  'dbtype' => 'mysql',
  'version' => '11.0.2.7',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'nextclouduser',
  'dbpassword' => 'nextcloudpassword',
  'logtimezone' => 'UTC',
  'installed' => true,
);
pi@raspberrypi:~ 

Nginx configuration is mentioned below.

server {
        listen 443 ssl;
        server_name cloud.domain.com;
        access_log /var/log/nginx/cloud.domain.com.access.log;
        error_log /var/log/nginx/cloud.domain.com.error.log;
        client_max_body_size 0;
        underscores_in_headers on;
        ssl on;
        ssl_certificate_key /home/pi/website-ssl-cert/private.key;
        ssl_certificate /home/pi/website-ssl-cert/certificate.crt;
        ssl_stapling on;
        ssl_stapling_verify on;
        location / {
                proxy_pass http://192.168.1.254:8888/nextcloud/;
            proxy_pass_header Authorization;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP  $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_http_version 1.1;
            proxy_set_header Connection "";
            proxy_buffering off;
            proxy_request_buffering off;
            client_max_body_size 0;
            proxy_read_timeout  36000s;
            proxy_redirect off;
            proxy_ssl_session_reuse off;
        }
}

Thanks for your help in advance.

I´m not fluent in nginx, so i may miss some obvious points, but the following error Message

has the nextcloud 2 times in there. What is strange, that you explicitly told the Reverseproxy to use 8888, yet the error says port 80. Is this error from the Apache error log or from your browser?

May you please post your apache config too?

Could be that you dont need to specify the ports under
'overwrite.cli.url' and
'trusted_domains'

it may even be, that it breaks something, i dont know, since i never tried it.

Thanks @Ascendancer for your support, this thread can be mark as closed.

Below is the config i’ve used in ngnix and it is working as expected.

server { listen 443 ssl; server_name nextcloud.domin.com; ssl on; ssl_certificate_key /website-ssl-cert/private.key; ssl_certificate /website-ssl-cert/certificate.crt; location /nextcloud/ { proxy_pass http://127.0.0.1:8888/nextcloud/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } location / { proxy_pass http://127.0.0.1:8888/nextcloud/; } }

Great to hear :slight_smile:
What was the issue then? Cant figure it our from you post. Just beeing curious.

Next time watch out and do not post the 'passwordsalt' and 'secret'. They are important for the security of your server!

@casKd-dev : Thanks for heads-up, appreciate it :slight_smile:

1 Like

Nginx was not able to handle URL with anything after the primary domain, so it was giving error

So i had add an directive to handle this issue,

Hope this will quench your curiosity. :vulcan_salute: