Switching from fastCGI to WSGI gives 502

Hello,

after a long time I now want to switch from fastCGI to WSGI but when changing the configuration according to the manual I only get a Bad Gateway when accessing the server.
Currently I run Seafile Pro 6.2.13

What I have done so far:

  • disabled fastcgi in the init script, which is confirmed working
  • changed the nginx config according to the manual (copy & paste the “location /” part
  • disabled webDAV (which seemed to be a problem according to some other threads)
  • restarted all services

No I can’t access Seafile via Seahub nor App and Client.

The seahub.error.log has mulitple entries like this (i replaced my IP addres):

2019/04/23 19:57:39 [error] 16833#0: *374 connect() failed (111: Connection refused) while connecting to upstream, client: 1.2.3.4, server: seafile.*, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8001/favicon.ico", host: "seafile.mydomain.de"

Without the changes mentioned above it was perfectly working.
Does anyone have any ideas?

Thank you in advance

The problem still occurs after multiple attempts. May anyone have a clue?

Here are my configurations:

nginx

server {
    listen 443;
    server_name cloud.*;
    ssl on;
    ssl_certificate     /etc/letsencrypt/live/cloud/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/cloud/privkey.pem;

    proxy_set_header X-Forwarded-For $remote_addr;

    add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";
    server_tokens off;

    location / {
         proxy_pass         http://127.0.0.1:8001;
         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_set_header   X-Forwarded-Host $server_name;
         proxy_read_timeout  1200s;
         proxy_http_version 1.1;

         # used for view/edit office file via Office Online Server
         client_max_body_size 0;

         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;
        proxy_send_timeout  36000s;
        send_timeout  36000s;
    }

    location /seafdav {
        fastcgi_pass    127.0.0.1:8081;
        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;

        client_max_body_size 0;
	#proxy_request_buffering off;

        access_log      /var/log/nginx/seafdav.access.log;
        error_log       /var/log/nginx/seafdav.error.log;
    }
 
    location /media {
        root /home/seafile/seafile-server-latest/seahub;
    }   
}

service

#!/bin/sh
 
### BEGIN INIT INFO
# Provides:          seafile-server
# Required-Start:    $local_fs $remote_fs $network
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts Seafile Server
# Description:       starts Seafile Server
### END INIT INFO
 
# Change the value of "user" to linux user name who runs seafile
user=seafile
 
# Change the value of "seafile_dir" to your path of seafile installation
# usually the home directory of $user
seafile_dir=/home/seafile
script_path=${seafile_dir}/seafile-server-latest
seafile_init_log=${seafile_dir}/logs/seafile.init.log
seahub_init_log=${seafile_dir}/logs/seahub.init.log
 
# Change the value of fastcgi to true if fastcgi is to be used
fastcgi=false
# Set the port of fastcgi, default is 8000. Change it if you need different.
fastcgi_port=8001
 
#
# Write a polite log message with date and time
#
echo -e "\n \n About to perform $1 for seafile at `date -Iseconds` \n " >> ${seafile_init_log}
echo -e "\n \n About to perform $1 for seahub at `date -Iseconds` \n " >> ${seahub_init_log}
 
case "$1" in
        start)
                sudo -u ${user} ${script_path}/seafile.sh ${1} >> ${seafile_init_log}
                if [ $fastcgi = true ];
                then
                        sudo -u ${user} ${script_path}/seahub.sh ${1}-fastcgi ${fastcgi_port} >> ${seahub_init_log}
                else
                        sudo -u ${user} ${script_path}/seahub.sh ${1} >> ${seahub_init_log}
                fi
                sudo ${script_path}/seaf-fuse.sh ${1} -o allow_other,uid=1000,gid=1000 /mnt/seafile-fuse >> ${seafile_init_log}
        ;;
        restart)
                sudo -u ${user} ${script_path}/seafile.sh ${1} >> ${seafile_init_log}
                if [ $fastcgi = true ];
                then
                        sudo -u ${user} ${script_path}/seahub.sh ${1}-fastcgi ${fastcgi_port} >> ${seahub_init_log}
                else
                        sudo -u ${user} ${script_path}/seahub.sh ${1} >> ${seahub_init_log}
                fi
        ;;
        stop)
                sudo ${script_path}/seaf-fuse.sh ${1} >> ${seafile_init_log}
                sudo -u ${user} ${script_path}/seahub.sh ${1} >> ${seahub_init_log}
                sudo -u ${user} ${script_path}/seafile.sh ${1} >> ${seafile_init_log}
        ;;
        *)
                echo "Usage: /etc/init.d/seafile-server {start|stop|restart}"
                exit 1
        ;;
esac

ccnet.conf

[General]
USER_NAME = secret
ID = secret
NAME = secret
SERVICE_URL = https://my.cloud.com

[Client]
PORT = 13419

[Database]
ENGINE = mysql
HOST = 127.0.0.1
PORT = 3306
USER = seafile
PASSWD = secret
DB = ccnet-db
CONNECTION_CHARSET = utf8

seafdav.conf

[WEBDAV]
enabled = false
port = 8081
fastcgi = false
host = 127.0.0.1
share_name = /seafdav

seafile.conf

[fileserver]
host = 127.0.0.1
port = 8082
max_download_dir_size=1000

[database]
type = mysql
host = 127.0.0.1
port = 3306
user = seafile
password = secret
db_name = seafile-db
connection_charset = utf8

seahub_settings.py

SECRET_KEY = secret

FILE_SERVER_ROOT = '/'


#Sonstiges
LANGUAGE_CODE = 'de'
SITE_TITLE = 'Cloud'

#Farben
BRANDING_CSS = 'custom/custom.css'
DESKTOP_CUSTOM_LOGO = 'custom/icon.png'
DESKTOP_CUSTOM_BRAND = 'Cloud'

#Datenbank
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'seahub-db',
        'USER': 'seafile',
        'PASSWORD': 'secret',
        'HOST': '127.0.0.1',
        'PORT': '3306'
    }
}


TEXT_PREVIEW_EXT = """ac, am, bat, c, cc, cmake, cpp, cs, css, diff, el, hpp, h, html, htm, java, js, json, less, make, org, php, pl, properties, py, rb, scala, script, sh, sql, txt, text, tex, vi, vim, xhtml, xml, log, csv, groovy, rst, patch, go, m"""
ENABLE_THUMBNAIL = True
ENABLE_VIDEO_THUMBNAIL = False #True
THUMBNAIL_VIDEO_FRAME_TIME = 5

ENABLE_TWO_FACTOR_AUTH = True

ENABLE_REPO_SNAPSHOT_LABEL = True

Hello again,

I tried to switch to WSGI a few more times. Still the same error as mentioned in the first post.
Is there noone to help? I bought the pro version, but I can’t use the current version, as no fastCGI is supported anymore @daniel.pan @Jonathan

Thank you
Jack

Please check the community manual. There are working configuration examples.

Hi Jack,

Are you sure, that you are using port 8001? In the manual (and in my configuration) port 8000 is used.
And maybe you’re missing the following entry in your “location /” statement:

proxy_set_header X-Forwarded-Proto https;

And what is in your gunicorn.conf. There should be the statement:

# default localhost:8000
bind = "0.0.0.0:8000"

Hi, thank you. But as I am still at 6.2.*, there is no gunicorn.conf. And if I change to port 8000 this results in

Cannot GET /

The missing statement in my nginx config changed nothing.

Hi @Jack hope you are not to much desesperate :slight_smile:

When you shifted to WSGI you didn’t realized that you “not standard port”, the 8001 will not have anymore effect after you changed fastcgi to false on the seafile init script/etc/init.d/seafile-server. Therefore the else statement will take over, instead of then statement:

 if [ $fastcgi = true ];
                then
                        sudo -u ${user} ${script_path}/seahub.sh ${1}-fastcgi ${fastcgi_port} >> ${seahub_init_log}
                else
                        sudo -u ${user} ${script_path}/seahub.sh ${1} >> ${seahub_init_log}

In that case, seafile will use the standard port, that means, the 8000.

If you modify nginx to listen on 8000, instead of 8001, should work.Change the line to:

proxy_pass http://127.0.0.1:8000;

One remark, you should comment the full block of /seafdav, because is still using fastcgi on nginx, which ist not correct, even if you don’t use it.

BTW, which nginx are you using? http2 gives a performance boost.

@DerDanilo could you please share again your seafile manual? I remember it had very good examples.

The official community manual is here:

https://manual.seafile.com/deploy/https_with_nginx.html

1 Like

The Seafile Community Manual is here.

Always keep it close at hand!

2 Likes

Thank you @jobenvil

I am using Nginx 1.6.2. As I wrote in the post above you, I get the message

Cannot GET /

in my browser, when switching to port 8000. I can’t activated http2 (to old version I guess), removed the seafdav part and compared my configuration to the manual. Still the same error :frowning:

Ok, let’s try this. Having stopped seafile & seahub process, do:

netstat -tulpen

later, start seafile and seahub and do again the earlier command.

In this way we should be able to see in which ports seafile is listening.

Post as well the output “ps -ef| grep -i seaf

This is the result of netstat -tulpen without seafile running:

Aktive Internetverbindungen (Nur Server)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       User       Inode       PID/Program name
tcp        0      0 127.0.0.1:3493          0.0.0.0:*               LISTEN      0          21122       1702/upsd       
tcp        0      0 0.0.0.0:25672           0.0.0.0:*               LISTEN      120        23614       1944/beam.smp   
tcp        0      0 0.0.0.0:9001            0.0.0.0:*               LISTEN      1001       2447232     18610/node      
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      113        2445516     18300/mysqld    
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      118        138251477   892/redis-server 12
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      0          16292       1081/rpcbind    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      0          155303681   8986/nginx -g daemo
tcp        0      0 127.0.0.1:24049         0.0.0.0:*               LISTEN      1001       155444138   5642/telegram-cli
tcp        0      0 0.0.0.0:4369            0.0.0.0:*               LISTEN      120        21692       1376/epmd       
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      0          21991       1386/sshd       
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      117        2468990     30436/postgres  
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      0          27028       4066/master     
tcp        0      0 0.0.0.0:40409           0.0.0.0:*               LISTEN      107        16337       1090/rpc.statd  
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      0          155303683   8986/nginx -g daemo
tcp        0      0 127.0.0.1:2812          0.0.0.0:*               LISTEN      0          2470108     29545/monit     
tcp6       0      0 :::8126                 :::*                    LISTEN      121        23730       2492/config.js  
tcp6       0      0 :::8384                 :::*                    LISTEN      0          138251160   924/syncthing   
tcp6       0      0 :::8000                 :::*                    LISTEN      121        26631       2496/node       
tcp6       0      0 :::5672                 :::*                    LISTEN      120        25500       1944/beam.smp   
tcp6       0      0 :::34121                :::*                    LISTEN      107        16341       1090/rpc.statd  
tcp6       0      0 :::3052                 :::*                    LISTEN      0          25574       1298/java       
tcp6       0      0 :::111                  :::*                    LISTEN      0          16295       1081/rpcbind    
tcp6       0      0 :::80                   :::*                    LISTEN      0          155303682   8986/nginx -g daemo
tcp6       0      0 :::22000                :::*                    LISTEN      0          138251167   924/syncthing   
tcp6       0      0 :::8080                 :::*                    LISTEN      121        25487       2494/node       
tcp6       0      0 :::6547                 :::*                    LISTEN      0          25573       1298/java       
tcp6       0      0 :::21                   :::*                    LISTEN      109        144636334   15501/proftpd: (acc
tcp6       0      0 :::22                   :::*                    LISTEN      0          22007       1386/sshd       
tcp6       0      0 ::1:5432                :::*                    LISTEN      117        2468989     30436/postgres  
tcp6       0      0 ::1:25                  :::*                    LISTEN      0          27029       4066/master     
tcp6       0      0 :::443                  :::*                    LISTEN      0          155303684   8986/nginx -g daemo
udp        0      0 0.0.0.0:52657           0.0.0.0:*                           0          21112       1692/snmpd      
udp        0      0 0.0.0.0:3559            0.0.0.0:*                           0          16532       874/dhclient    
udp        0      0 0.0.0.0:21027           0.0.0.0:*                           0          138251169   924/syncthing   
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           105        21587       1308/avahi-daemon: 
udp        0      0 0.0.0.0:8125            0.0.0.0:*                           121        23731       2492/config.js  
udp        0      0 0.0.0.0:41617           0.0.0.0:*                           105        21589       1308/avahi-daemon: 
udp        0      0 0.0.0.0:47713           0.0.0.0:*                           107        16335       1090/rpc.statd  
udp        0      0 0.0.0.0:48300           0.0.0.0:*                           0          138251162   924/syncthing   
udp        0      0 0.0.0.0:68              0.0.0.0:*                           0          16563       874/dhclient    
udp        0      0 0.0.0.0:111             0.0.0.0:*                           0          16288       1081/rpcbind    
udp        0      0 10.8.0.1:123            0.0.0.0:*                           0          20461       1310/ntpd       
udp        0      0 192.168.178.48:123      0.0.0.0:*                           0          20460       1310/ntpd       
udp        0      0 127.0.0.1:123           0.0.0.0:*                           0          20459       1310/ntpd       
udp        0      0 0.0.0.0:123             0.0.0.0:*                           0          20443       1310/ntpd       
udp        0      0 127.0.0.1:161           0.0.0.0:*                           0          21114       1692/snmpd      
udp        0      0 0.0.0.0:832             0.0.0.0:*                           0          16291       1081/rpcbind    
udp        0      0 127.0.0.1:842           0.0.0.0:*                           0          16331       1090/rpc.statd  
udp        0      0 0.0.0.0:1194            0.0.0.0:*                           0          17763       1186/openvpn    
udp6       0      0 :::3052                 :::*                                0          25716       1298/java       
udp6       0      0 :::21027                :::*                                0          138251165   924/syncthing   
udp6       0      0 :::5353                 :::*                                105        21588       1308/avahi-daemon: 
udp6       0      0 :::22000                :::*                                0          138251158   924/syncthing   
udp6       0      0 :::55094                :::*                                0          138251154   924/syncthing   
udp6       0      0 :::56942                :::*                                105        21590       1308/avahi-daemon: 
udp6       0      0 :::40903                :::*                                0          16533       874/dhclient    
udp6       0      0 :::60657                :::*                                0          25708       1298/java       
udp6       0      0 :::111                  :::*                                0          16293       1081/rpcbind    
udp6       0      0 ::1:123                 :::*                                0          20462       1310/ntpd       
udp6       0      0 :::123                  :::*                                0          20444       1310/ntpd       
udp6       0      0 :::33163                :::*                                107        16339       1090/rpc.statd  
udp6       0      0 :::832                  :::*                                0          16294       1081/rpcbind

When seafile is started, these two lines are added:

tcp        0      0 127.0.0.1:8082          0.0.0.0:*               LISTEN      1000       155529922   14665/seaf-server
tcp6       0      0 127.0.0.1:9200          :::*                    LISTEN      1000       155530137   14661/java

ps -ef| grep -i seaf outputs

error: conflicting format options

but when I remove the f argument, I get

root      6935  0.0  0.0  47828  3172 pts/0    S    17:53   0:00  |                   \_ su - seafile
seafile   6936  0.0  0.0  24976  5516 pts/0    S+   17:53   0:00  |                       \_ -su
root     16566  0.0  0.0  14216  2228 pts/3    S+   21:32   0:00                      \_ grep -i seaf
seafile  14643  0.0  0.0  72212  3768 ?        Ss   21:30   0:00 /home/seafile/seafile-pro-server-6.2.13/seafile/bin/seafile-controller -c /home/seafile/ccnet -d /home/seafile/seafile-data -F /home/seafile/conf
seafile  14660  0.6  0.1 461664 37420 ?        Sl   21:30   0:00  \_ /usr/bin/python2.7 -m seafevents.main --config-file /home/seafile/conf/seafevents.conf --logfile /home/seafile/logs/seafevents.log -P /home/seafile/pids/seafevents.pid
seafile  14729  0.0  0.0      0     0 ?        Z    21:30   0:00  |   \_ [sh] <defunct>
seafile  14661  5.6  0.9 2586620 312244 ?      Sl   21:30   0:05  \_ /usr/bin/java -Xms256m -Xmx1g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+DisableExplicitGC -Dfile.encoding=UTF-8 -Djna.nosys=true -Des.path.home=/home/seafile/seafile-pro-server-6.2.13/pro/elasticsearch -cp /home/seafile/seafile-pro-server-6.2.13/pro/elasticsearch/lib/elasticsearch-2.4.5.jar:/home/seafile/seafile-pro-server-6.2.13/pro/elasticsearch/lib/* org.elasticsearch.bootstrap.Elasticsearch start -Des.path.logs=/home/seafile/logs -Des.path.data=/home/seafile/pro-data/search/data -Des.network.host=127.0.0.1 -Des.insecure.allow.root=true -p /home/seafile/pids/elasticsearch.pid
seafile  14646  0.0  0.0 194240  9768 ?        Ss   21:30   0:00 ccnet-server -F /home/seafile/conf -c /home/seafile/ccnet -f /home/seafile/logs/ccnet.log -d -L /home/seafile -P /home/seafile/pids/ccnet.pid
seafile  14665  0.0  0.0 1147700 11028 ?       Ssl  21:30   0:00 seaf-server -F /home/seafile/conf -c /home/seafile/ccnet -d /home/seafile/seafile-data -l /home/seafile/logs/seafile.log -P /home/seafile/pids/seaf-server.pid -L /home/seafile
root     14915  0.0  0.0 266604  1668 ?        Ssl  21:30   0:00 /home/seafile/seafile-pro-server-6.2.13/seafile/bin/seaf-fuse -c /home/seafile/ccnet -d /home/seafile/seafile-data -F /home/seafile/conf -l /home/seafile/logs/seaf-fuse.log -o allow_other,uid=1000,gid=1000 /mnt/seafile-fuse

I made it!! Looking at the ports I noticed port 8000 being used by another application. And yes, the onlyoffice documentserver was using port 8000. Killing the documentserver and restarting as well nginx and seafile made it work!! :grinning:

Thank you for your hints :slight_smile:

good catch, I was observing the same aka node. :muscle::+1:

the hint was also here.