Running Seafile under a subdomain using Nginx

Hello!

I have installed Seafile on an Ubuntu 16.04 instance on Lightsail by AWS Amazon and everything seems to work as it should except for the reverse proxy where I am trying to make Seafile accessible at cloud (.) mydomain (.) com rather than mydomain (.) com.

Goal:
Instead of accessing Seafile at:

mydomain.com

I want to access it at:

cloud.mydomain.com

Here are my config files:

/etc/nginx/sites-available/seafile.conf:

    server {
    listen 80;
    server_name cloud.MYDOMAINNAME.com;

    proxy_set_header X-Forwarded-For $remote_addr;

    location / {
         proxy_pass         http://127.0.0.1:8000;
         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;

         # 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;
    }

# If you are using [FastCGI](http://en.wikipedia.org/wiki/FastCGI),
# which is not recommended, you should use the following config for location `/`.
#
#    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   REMOTE_ADDR         $remote_addr;
#          fastcgi_read_timeout 36000;
#
#         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_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_connect_timeout  36000s;
        proxy_read_timeout  36000s;
        proxy_send_timeout  36000s;

        send_timeout  36000s;
    }
    location /media {
        root /home/ubuntu/seafile/seafile-server-latest/seahub;
    }
}

/home/USER/seafile/conf/ccnet.conf:

[General]
USER_NAME = MY-USER-NAME
ID = SOME-STRING
NAME = MY-NAME
SERVICE_URL = http://cloud.MYDOMAINNAME.com

[Client]
PORT = 13419

[Database]
ENGINE = mysql
HOST = 127.0.0.1
PORT = 3306
USER = seafile
PASSWD = MY-VERY-LONG-PASSWORD
DB = ccnet-db
CONNECTION_CHARSET = utf8

/home/USER/seafile/conf/seahub_settings.py:

SECRET_KEY = "SECRET-KEY"
FILE_SERVER_ROOT = 'http://cloud.MYDOMAINNAME.com'
DATABASES = {
    'default':  {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'seahub-db',
        'USER': 'seafile',
        'PASSWORD': 'MY-LONG-PASSWORD'
        'HOST': '127.0.0.1',
        'PORT': '3306'
    }
}

symbolic link made for seafile.conf in available-sites in enabled-sites using

ln -s /etc/nginx/sites-available/seafile.conf /etc/nginx/sites-enabled/seafile.conf

Nginx directory:

  nginx
    |
    |- /conf.d
    |- fastcgi_params
    |- fastcgi.conf
    |- koi-utf
    |- koi-win
    |- mime.types
    |- nginx.conf
    |- proxy_params
    |- scgi_params
    |- /sites-available
    |     |- seafile.conf
    |
    |- /sites-enabled
    |     |- seafile.conf
    |
    |- /snippets
    |- uwsgi_params
    |- win-utf

status output for ufw:

ubuntu@IP-ADDRESS:~$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
22                         ALLOW       Anywhere
2222/tcp                   ALLOW       Anywhere
22/tcp                     ALLOW       Anywhere
80/tcp                     ALLOW       Anywhere
443/tcp                    ALLOW       Anywhere
21/tcp                     ALLOW       Anywhere
443                        ALLOW       Anywhere
8000                       ALLOW       Anywhere
8082                       ALLOW       Anywhere
80                         ALLOW       Anywhere
Nginx Full                 ALLOW       Anywhere
22 (v6)                    ALLOW       Anywhere (v6)
2222/tcp (v6)              ALLOW       Anywhere (v6)
22/tcp (v6)                ALLOW       Anywhere (v6)
80/tcp (v6)                ALLOW       Anywhere (v6)
443/tcp (v6)               ALLOW       Anywhere (v6)
21/tcp (v6)                ALLOW       Anywhere (v6)
443 (v6)                   ALLOW       Anywhere (v6)
8000 (v6)                  ALLOW       Anywhere (v6)
8082 (v6)                  ALLOW       Anywhere (v6)
80 (v6)                    ALLOW       Anywhere (v6)
Nginx Full (v6)            ALLOW       Anywhere (v6)

output of sudo systemctl status nginx:

ubuntu@IP-ADDRESS:~$ sudo systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2019-01-13 12:03:23 UTC; 36min ago
  Process: 2864 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
  Process: 2876 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 2870 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 2879 (nginx)
    Tasks: 2
   Memory: 1.9M
      CPU: 29ms
   CGroup: /system.slice/nginx.service
           ├─2879 nginx: master process /usr/sbin/nginx -g daemon on; master_process on
           └─2880 nginx: worker process

Jan 13 12:03:23 ip-172-26-8-155 systemd[1]: Starting A high performance web server and a reverse proxy     server...
Jan 13 12:03:23 ip-172-26-8-155 systemd[1]: nginx.service: Failed to read PID from file /run/nginx.pid: Invalid argument
Jan 13 12:03:23 ip-172-26-8-155 systemd[1]: Started A high performance web server and a reverse proxy server.

Any and all help is appreciated. :slight_smile:

This topic can be marked as solved.

I never figured out what the problem was but I was able to get it to work by spinning up a new instance and following this tutorial:

https://www.howtoforge.com/tutorial/seafile-on-ubuntu-with-nginx/
1 Like