Seahub (fastcgi) with nginx does not work properly

I have just installed Seafile-server-6.0.6 on my VPS with Ubuntu 14.04. When I start my server with ./seahub.sh start on port 8000, it works fine and I can access it with http://mydomain:8000. But since it is a remote server, I set up HTTPS to ensure the security, but seemingly seahub only works with HTTPS with nginx (or apache) on fastcgi mode.

(If there is some way that HTTPS works with the built-in python server, that would solve my problem, but I don’t know how to configure, yet nothing about it on server manual)

So I configure the seahub with HTTPS on nginx by following the server manal and open a port on 9000 with https (port is not the problem, I have tried 443, they are the same)
The problem is when I access through https://mydomain:9000 the web page did load but the interface is very ugly with no images, more importantly, besides logging in, I can do nothing. (seems like images and CSS and JS all failed to load up) I tried to open another port on nginx without HTTPS, the result is the same (but as I said, using the built-in 8000 port without fastcgi works properly so I think the problem is fastcgi)

Please help me to solve the problem. thx for all

You can try to deploy seafile server with docker. It would automatically configure nginx and https for you.

Hi @lewisxy,

may I have a look at your nginx configuration?
There is usually no problem on deploying seafile behind nginx. Maybe there is just a small error in the config…

This is the configuration in /etc/nginx/sites-enabled

server {
    server_tokens off;
    listen 9001;
    server_name mydomain;

    proxy_set_header X-Forwarded-For $remote_addr;

    location / {
        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;

        access_log      /var/log/nginx/seahub.access_nonhttp.log;
        error_log       /var/log/nginx/seahub.error_nonhttp.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 /media {
        root /root/seafile/seafile-server-latest/seahub;
    }
}

server {
    server_tokens off;
    listen 9000;
    server_name mydomain;

    ssl on;
    ssl_certificate /root/ssl/chained.pem;
    ssl_certificate_key /root/ssl/domain.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA;
    ssl_session_cache shared:SSL:50m;
    ssl_prefer_server_ciphers on;

    proxy_set_header X-Forwarded-For $remote_addr;

    location / {
        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      /var/log/nginx/seahub.access.log;
        error_log       /var/log/nginx/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 /media {
        root /root/seafile/seafile-server-latest/seahub;
    }
}

server {
    server_tokens off;
    listen 80;
    server_name mydomain;

    location /.well-known/acme-challenge/ {
        alias /usr/share/nginx/html/challenges/;
        try_files $uri =404;
    }

	location / {
        rewrite ^ https://$http_host$request_uri? permanent;
    }
}

Below is nginx.conf I don’t think I make any change to that file

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
	worker_connections 768;
	# multi_accept on;
}

http {

	##
	# Basic Settings
	##

	sendfile on;
	tcp_nopush on;
	tcp_nodelay on;
	keepalive_timeout 65;
	types_hash_max_size 2048;
	# server_tokens off;

	# server_names_hash_bucket_size 64;
	# server_name_in_redirect off;

	include /etc/nginx/mime.types;
	default_type application/octet-stream;

	##
	# Logging Settings
	##

	access_log /var/log/nginx/access.log;
	error_log /var/log/nginx/error.log;

	##
	# Gzip Settings
	##

	gzip on;
	gzip_disable "msie6";

	# gzip_vary on;
	# gzip_proxied any;
	# gzip_comp_level 6;
	# gzip_buffers 16 8k;
	# gzip_http_version 1.1;
	# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

	##
	# nginx-naxsi config
	##
	# Uncomment it if you installed nginx-naxsi
	##

	#include /etc/nginx/naxsi_core.rules;

	##
	# nginx-passenger config
	##
	# Uncomment it if you installed nginx-passenger
	##
	
	#passenger_root /usr;
	#passenger_ruby /usr/bin/ruby;

	##
	# Virtual Host Configs
	##

	include /etc/nginx/conf.d/*.conf;
	include /etc/nginx/sites-enabled/*;
}


#mail {
#	# See sample authentication script at:
#	# http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#	# auth_http localhost/auth.php;
#	# pop3_capabilities "TOP" "USER";
#	# imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#	server {
#		listen     localhost:110;
#		protocol   pop3;
#		proxy      on;
#	}
# 
#	server {
#		listen     localhost:143;
#		protocol   imap;
#		proxy      on;
#	}
#}

Try to change your “media” location to this:

location /media {
    rewrite ^/media(.*)$ /media$1 break;
    root /root/seafile/seafile-server-latest/seahub;
}

alternatively, you could debug in your browser (for chrome and firefox press F12, look at console).
There you should see, how the links look like, that seafile tries to load css etc.

After debugging in browser, I discovered that all the JSs and CSSs failed to load with HTTP 403/404/500. So I think that problem is nginx is not permitted to access those files since they are located in /root folder. Eventually, it works after I moved the entire seafile directory to /opt/ from my root directory, both upload and download on webpage functioned properly with HTTPS.

Thank you all for help!

1 Like