NC not running on nginx?

Hello

is there someone who has NC successfully installed on nginx?

Kind regards
//nephilim

Should work the same way as it did with ownCloud :blush:
https://docs.nextcloud.com/server/9/admin_manual/installation/nginx_nextcloud_9x.html

2 Likes

Hi

I thought so as well but it doesn’t woirk for me. I did the same preparations as for oC. When I call my site, Chrome is telling me “ERR_CONNECTION_REFUSED”. No further messages. No idea where to start with my investigation. I used the config file and adapted the pathes and server name values and modified the document root.

I tried to do a complete fresh installation using nginx in R-Pi 2 B. Previously it worked with oC and I don’t want to install oC first and afterwards I do the migration to Nextcloud.

Do you have done a fresh and successful installation of Nextcloud on nginx?

Kind regards
//neph
Von unterwegs…

Cat /var/log/nginx/error.log

Anything usefull in there?

Hej,

just this: invalid number of arguments in "location" directive in /etc/nginx/sites-enabled/default:81. But this I “solved” by removing /etc/nginx/sites-enabled/default. This error prvented the nginx service to start. And as it just looked to me like a link to > /etc/nginx/available-sites/default, I removed it. Once it was removed, the nginx service started again.

Maybe this is the reason for this issue? The missing default in /etc/nginx/sites-enabled/ ?

Kind regards
//neph

I am not in front of mine right now.
But there is something wrong in the default file itself with the syntax. It is validated uppon restart.

What is the content of the mentioned line 81?

Nextcloud needs a special nginx configuration, as I linked it in the comment above.
Therefore the default configuration nginx provides isn’t working with Nextcloud.
I would simply deactivate the default configuration and use the one provided by the Nextcloud documentation.

But I’m glad you were able to solve the problem! :relaxed:

Is it solved?
I am not sure yet because he was refering to the NGINX start.
its starting right now but according to my understanding he should be missing some config now.

lets wait for nephilim´s report

Exactly. I suggest to delete the file caused a new issue. In category installation of this forum you’ll find a new ticket of mine, stating NC is not working when I call it.

Looks like I need to do a fresh installation. :frowning:

@irgendwie: I am aware oft the nginx config file. :wink:

Kind regards
//neph
Von unterwegs…

Hello

well, I did a complete fresh installation and I stuck again. Here are the steps I did so far. Hope, you can check and be able to figure out what I missed to do or where I made a mistake.

sudo bash
apt-get update && apt-get upgrade
apt-get install nginx
sed -e "s/worker_processes 4;/worker_processes 1;/g" /etc/nginx/nginx.conf > sudo /etc/nginx/nginx.conf
sed -e "s/worker_connections 768;/worker_connections 128;/g" /etc/nginx/nginx.conf > sudo /etc/nginx/nginx.conf
exit

Then I created the share for server cert and key:

sudo su
cd /etc/nginx
mkdir ssl

Now moved server cert and key to /etc/nginx/ssl
adapted /etc/nginx/sites-available/default

server block looks now this way:

(...)
# Default server configuration
#
server {
        listen              80;
        listen              443 ssl;
        server_name         sub.domain.com;
        ssl_certificate     /etc/nginx/ssl/server.crt;
        ssl_certificate_key /etc/nginx/ssl/server.key;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;
(...)

Called https://sub.domain.com:1444 and it worked fine. Saw my nginx welcome page (from outside my home network). Fine so far!


Part2:

Now I installed PHP modules and MySQL

sudo apt-get install php5 php5-fpm php-pear php5-common php5-mcrypt php5-cli php5-gd php5-curl php-apc memcached php5-memcache php5-json php5-imagick php5-intl
sudo apt-get install mysql-server php5-mysql

Part 3

Then I went to /var/www and unzipped the nextcloud-9.0.50.zip

pi@nextcloud:/var/www $ ls -alF
total 33020
drwxr-xr-x  4 pi   pi       4096 Jun 16 18:19 ./
drwxr-xr-x 12 root root     4096 Jun 16 17:37 ../
drwxr-xr-x  2 root root     4096 Jun 16 17:37 html/
drwxr-xr-x 14 pi   pi       4096 Jun 14 11:44 nextcloud/
-rw-r--r--  1 pi   pi   33795553 Jun 16 17:47 nextcloud-9.0.50.zip
pi@nextcloud:/var/www $

Part 4

Then I adapted the nginx config like it follows. I changed the server name, path to document root and modified the pathes for SSL. Please see beneath:

upstream php-handler {
    server 127.0.0.1:9000;
    #server unix:/var/run/php5-fpm.sock;
}

server {
    listen 80;
    server_name sub.domain.com;
    # enforce https
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;
    server_name sub.domain.com;

    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;

    # Add headers to serve security related headers
    # Before enabling Strict-Transport-Security headers please read into this
    # topic first.
    # add_header Strict-Transport-Security "max-age=15768000;
    # includeSubDomains; preload;";
    add_header X-Content-Type-Options nosniff;
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Robots-Tag none;
    add_header X-Download-Options noopen;
    add_header X-Permitted-Cross-Domain-Policies none;

    # Path to the root of your installation
    root /var/www/nextcloud/;

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

(...)

Once this was done, I cannot start the nginx service anylonger. :frowning:

Error log is showing:

2016/06/16 18:33:51 [emerg] 29625#0: invalid number of arguments in "location" directive in /etc/nginx/sites-enabled/default:81

pi@nextcloud:~ $ cd /etc/nginx/sites-enabled
pi@nextcloud:/etc/nginx/sites-enabled $ ls -alF
total 8
drwxr-xr-x 2 root root 4096 Jun 16 17:37 ./
drwxr-xr-x 7 root root 4096 Jun 16 17:41 ../
lrwxrwxrwx 1 root root   34 Jun 16 17:37 default -> /etc/nginx/sites-available/default
pi@nextcloud:/etc/nginx/sites-enabled $

pi@nextcloud:/etc/nginx/sites-enabled $ cat default
    upstream php-handler {
        server 127.0.0.1:9000;
        #server unix:/var/run/php5-fpm.sock;
    }

    server {
        listen 80;
        server_name sub.domain.com;
        # enforce https
        return 301 https://$server_name$request_uri;
    }

    server {
        listen 443 ssl;
        server_name sub.domain.com;

        ssl_certificate /etc/nginx/ssl/server.crt;
        ssl_certificate_key /etc/nginx/ssl/server.key;

        # Add headers to serve security related headers
        # Before enabling Strict-Transport-Security headers please read into this
        # topic first.
        # add_header Strict-Transport-Security "max-age=15768000;
        # includeSubDomains; preload;";
        add_header X-Content-Type-Options nosniff;
        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-XSS-Protection "1; mode=block";
        add_header X-Robots-Tag none;
        add_header X-Download-Options noopen;
        add_header X-Permitted-Cross-Domain-Policies none;

        # Path to the root of your installation
        root /var/www/nextcloud/;

        location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
        }

        # The following 2 rules are only needed for the user_webfinger app.
        # Uncomment it if you're planning to use this app.
        #rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
        #rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json
        # last;

        location = /.well-known/carddav { return 301
         $scheme://$host/remote.php/dav; }
        location = /.well-known/caldav { return 301
         $scheme://$host/remote.php/dav; }

        location /.well-known/acme-challenge { }

        # set max upload size
        client_max_body_size 512M;
        fastcgi_buffers 64 4K;

        # Disable gzip to avoid the removal of the ETag header
        gzip off;

        # Uncomment if your server is build with the ngx_pagespeed module
        # This module is currently not supported.
        #pagespeed off;

        error_page 403 /core/templates/403.php;
        error_page 404 /core/templates/404.php;

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

        location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
            deny all;
        }
        location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
            deny all;
        }

        location ~
        ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater
        /.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
            include fastcgi_params;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param HTTPS on;
            #Avoid sending the security headers twice
            fastcgi_param modHeadersAvailable true;
            fastcgi_param front_controller_active true;
            fastcgi_pass php-handler;
            fastcgi_intercept_errors on;
            fastcgi_request_buffering off;
        }

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

        # Adding the cache control header for js and css files
        # Make sure it is BELOW the PHP block
        location ~* \.(?:css|js)$ {
            try_files $uri /index.php$uri$is_args$args;
            add_header Cache-Control "public, max-age=7200";
            # Add headers to serve security related headers (It is intended to
            # have those duplicated to the ones above)
            # Before enabling Strict-Transport-Security headers please read into
            # this topic first.
            # add_header Strict-Transport-Security "max-age=15768000;
            #  includeSubDomains; preload;";
            add_header X-Content-Type-Options nosniff;
            add_header X-Frame-Options "SAMEORIGIN";
            add_header X-XSS-Protection "1; mode=block";
            add_header X-Robots-Tag none;
            add_header X-Download-Options noopen;
            add_header X-Permitted-Cross-Domain-Policies none;
            # Optional: Don't log access to assets
            access_log off;
        }

        location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {
            try_files $uri /index.php$uri$is_args$args;
            # Optional: Don't log access to other assets
            access_log off;
        }
    }
pi@nextcloud:/etc/nginx/sites-enabled $

Your assistance is highly appreciated.

Kind regards
//nephilim

1 Like

Hello

any idea how I can get this fixed?

Kind regards
//neph

My guess: this line should not contain any line-breaks:

location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34]).php(?:$|/) {

Haven’t checked further. Maybe there are more wrong line-breaks in the config. Nginx should tell, when you test it’s configuration with

nginx -t

Hello Bernie_O

great hint. Thank you so much.

The error in line 81 is now solved. WHen I now test the configuration I receive this:

root@nginx:/home/pi# nginx -t nginx: [emerg] unknown directive "fastcgi_request_buffering" in /etc/nginx/sites-enabled/default:91 nginx: configuration file /etc/nginx/nginx.conf test failed root@nginx:/home/pi#

The entry in line 91:

fastcgi_request_buffering off;

Set it to ON it won’t work neither. But removing it from config the test ends successful. But I am not sure if this is required. Do you know that? Or do you know someone who could know that?

Kind regards
//neph

You need nginx >= 1.7.11 for this directive: http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_request_buffering

You probably have an older version of nginx running. You can check your version of nginx with:

nginx -v

Nextcloud will also work without this directive. It is only necessary for upload of very big files (several GB).