[SOLVED] Setting up Nextcloud with NGiNX Issues


So I am looking to install Nextcloud on the following environment:

Ubuntu 16.04
PHP 7.2 (modules installed)
NGiNX (php-fpm installed)

This environment is of course running behind an NGiNX reverse proxy since I have other servers on the network running as well. The reverse proxy has cerbot installed and is running SSL termination.

I am using the following configuration on the Nextcloud server:


But right now I am just hitting the default “Welcome to NGiNX” page. I have /var/www/cloud, the permissions are correctly set and everything. What am I doing wrong?


server {
listen 80;
listen [::]:80;
server_name cloud.domain.com;

server {
listen 80 default_server;
listen [::]:80 default_server;
server_name cloud.domain.com;

Could it be due to wrong port definitions? It’s port 80 twice instead of port 80 and port 443.


It shouldn’t be the wrong ports, the SSL is terminated and then the connection is forwarded HTTP.


Sorry, I don’t see where you forward you forward from port 443 to port 80 to terminate SSL. :thinking:

Additional idea (not related to “welcome to nginx”):
I read that for security reason you should actually use $request_uri instead of $uri

location / {
    rewrite ^ /index.php$request_uri;


location ~ \.(?:css|js|woff|svg|gif)$ {
    try_files $uri /index.php$request_uri$is_args$args;


There are multiple servers, the SSL termination is done on the Reverse Proxy server, the config I posted is the one where Nextcloud is hosted.


I am confused by your second point, I assume you are referring to this?

location ~ ^/(?:updater|ocs-provider)(?:$|/) {
    try_files $uri/ =404;
    index index.php;


Okay, I didn’t know about SSL termination, sorry about that.

Further (maybe stupid) ideas:

  • loaded the correct config (just to make sure you didn’t edit the config that is not loaded actually)
  • php handler really listening on port 9000 and you don’t use the socket
  • restarted nginx after config edit

Oh and I had an issue in the past where the browser cached the content. I just noticed that when using a different browser. Clearing the browser cash and doing a full reload of the page (CTRL + R) helped with then.

Regarding my suggestion:
Your config reads

location / {
    rewrite ^ /index.php$uri;

I suggest

location / {
    rewrite ^ /index.php$request_uri;


I am using incognito mode in the browser to test this but I did clear out browser entirely but the issue remains.


Since there are two server blocks with the same server_name nginx will pick the first one (which is basically an empty block) serving a request with that server name. Have you tried deleting or commenting out the first server block:

server {
    listen 80;
    listen [::]:80;
    server_name cloud.domain.com;

EDIT: don‘t forget to let nginx reload the configuration files with nginx -s reload


So I deleted one block, so this is my config now:


But now the error I am getting is Bad Gateway error.


Are you sure php-fpm is configured to listen at
Have a look in the configuration file /etc/php/7.2/fpm/pool.d/www.conf where php is listening.


Ok that was it.


Good to hear it is working now :slight_smile: