Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nginx shows default landing page after fresh install #2774

Open
liblzmasapue opened this issue Oct 18, 2022 · 12 comments
Open

nginx shows default landing page after fresh install #2774

liblzmasapue opened this issue Oct 18, 2022 · 12 comments

Comments

@liblzmasapue
Copy link

Hello there,

We followed the step by step install procedure from https://udata.readthedocs.io/en/latest/installation/ and made it through the whole installation process.

Leaving the default values found in the sample configuration files provided, after install when we try to access our udata server locally via it's IP address, we do get nginx default server landing page.

Adding the server's IP as is :

server {
listen 80;
server_name data.example.com 10.22.33.44;

in /etc/nginx/sites-available/data.example.com file brings us to a "internal server error" page when refreshing, after reloading the nginx service.

Removing the IP in server_name brings us back to nginx default landing page.

image

nginx error logs are empty. We didn't encounter any specific error while following the install procedure.
nginx -t says everything is fine.

Is there something we should check ?

We are using a freshly installed Ubuntu Server 18.04.

Thanks a lot.

@maudetes
Copy link
Contributor

Hello !

This documentation for deployment is shown as an example and may not work as is on all environments.

It will be difficult for us to help you without any errors log. However, when you specify the server in /etc/nginx/sites-available/data.example.com and you get an "internal server error", you should probably look at the uwsgi logs for any error.

@liblzmasapue
Copy link
Author

liblzmasapue commented Oct 19, 2022

Hey and thanks for your help !

We do have an error in our uwsgi logs :

Wed Oct 19 09:35:49 2022 - writing pidfile to /run/uwsgi/app/udata-front/pid
Wed Oct 19 09:35:49 2022 - detected binary path: /usr/bin/uwsgi-core
Wed Oct 19 09:35:49 2022 - dropping root privileges as early as possible
Wed Oct 19 09:35:49 2022 - setgid() to 33
Wed Oct 19 09:35:49 2022 - setuid() to 1001
Wed Oct 19 09:35:49 2022 - chdir() to /srv/udata
Wed Oct 19 09:35:49 2022 - your processes number limit is 15418
Wed Oct 19 09:35:49 2022 - limiting address space of processes...
Wed Oct 19 09:35:49 2022 - your process address space limit is 1073741824 bytes (1024 MB)
Wed Oct 19 09:35:49 2022 - your memory page size is 4096 bytes
Wed Oct 19 09:35:49 2022 - detected max file descriptor number: 1024
Wed Oct 19 09:35:49 2022 - lock engine: pthread robust mutexes
Wed Oct 19 09:35:49 2022 - thunder lock: disabled (you can enable it with --thunder-lock)
Wed Oct 19 09:35:49 2022 - uwsgi socket 0 bound to UNIX address /run/uwsgi/app/udata-front/socket fd 3
Wed Oct 19 09:35:49 2022 - uwsgi socket 1 bound to UNIX address /tmp/udata-front.sock fd 5
Wed Oct 19 09:35:49 2022 - dropping root privileges after socket binding
Wed Oct 19 09:35:49 2022 - Python version: 3.6.9 (default, Jun 29 2022, 11:45:57)  [GCC 8.4.0]
Wed Oct 19 09:35:49 2022 - PEP 405 virtualenv detected: /srv/udata
Wed Oct 19 09:35:49 2022 - Set PythonHome to /srv/udata
Wed Oct 19 09:35:49 2022 - *** Python threads support is disabled. You can enable it with --enable-threads ***
Wed Oct 19 09:35:49 2022 - Python main interpreter initialized at 0x5640d3b87d60
Wed Oct 19 09:35:49 2022 - dropping root privileges after plugin initialization
Wed Oct 19 09:35:49 2022 - your server socket listen backlog is limited to 100 connections
Wed Oct 19 09:35:49 2022 - your mercy for graceful operations on workers is 60 seconds
Wed Oct 19 09:35:49 2022 - mapped 436608 bytes (426 KB) for 5 cores
Wed Oct 19 09:35:49 2022 - *** Operational MODE: preforking ***
Wed Oct 19 09:35:49 2022 - added /srv/udata/bin/ to pythonpath.
Wed Oct 19 09:35:49 2022 - dropping root privileges after application loading
Wed Oct 19 09:35:49 2022 - *** uWSGI is running in multiple interpreter mode ***
Wed Oct 19 09:35:49 2022 - spawned uWSGI master process (pid: 47901)
Wed Oct 19 09:35:49 2022 - spawned uWSGI worker 1 (pid: 47908, cores: 1)
Wed Oct 19 09:35:49 2022 - spawned uWSGI worker 2 (pid: 47909, cores: 1)
Wed Oct 19 09:35:49 2022 - spawned uWSGI worker 3 (pid: 47910, cores: 1)
Wed Oct 19 09:35:49 2022 - spawned uWSGI worker 4 (pid: 47911, cores: 1)
Wed Oct 19 09:35:49 2022 - spawned uWSGI worker 5 (pid: 47912, cores: 1)
Wed Oct 19 09:35:49 2022 - *** Stats server enabled on /tmp/udata-front-stats.sock fd: 19 ***
Wed Oct 19 09:35:49 2022 - mapping worker 4 to CPUs: 0
Wed Oct 19 09:35:49 2022 - mapping worker 3 to CPUs: 0
Wed Oct 19 09:35:49 2022 - mapping worker 5 to CPUs: 0
Wed Oct 19 09:35:49 2022 - mapping worker 2 to CPUs: 0
Wed Oct 19 09:35:49 2022 - mapping worker 1 to CPUs: 0
ModuleNotFoundError: No module named 'udata'
Wed Oct 19 09:35:49 2022 - unable to load app 0 (mountpoint='') (callable not found or import error)
Wed Oct 19 09:35:49 2022 - *** no app loaded. going in full dynamic mode ***
ModuleNotFoundError: No module named 'udata'
Wed Oct 19 09:35:49 2022 - unable to load app 0 (mountpoint='') (callable not found or import error)
Wed Oct 19 09:35:49 2022 - *** no app loaded. going in full dynamic mode ***
ModuleNotFoundError: No module named 'udata'
Wed Oct 19 09:35:49 2022 - unable to load app 0 (mountpoint='') (callable not found or import error)
Wed Oct 19 09:35:49 2022 - *** no app loaded. going in full dynamic mode ***
ModuleNotFoundError: No module named 'udata'
Wed Oct 19 09:35:49 2022 - unable to load app 0 (mountpoint='') (callable not found or import error)
Wed Oct 19 09:35:49 2022 - *** no app loaded. going in full dynamic mode ***
ModuleNotFoundError: No module named 'udata'
Wed Oct 19 09:35:49 2022 - unable to load app 0 (mountpoint='') (callable not found or import error)
Wed Oct 19 09:35:49 2022 - *** no app loaded. going in full dynamic mode ***

From what I understand, the issue might be we installed udata through a python3.7 virtual env, and uwsgi is using python3.6.

Here's a sample of our uwsgi conf file (same as provided in the install docs actually) :

##
# uWSGI configuration for data.example.com front
##

[uwsgi]
master= true

; Python / Environment configuration
plugin = python3
home = /srv/udata
chdir = %(home)
virtualenv = %(home)
pythonpath = %(home)/bin
module = udata.wsgi
callable = app

; Sockets and permissions
stats = /tmp/udata-front-stats.sock
socket = /tmp/udata-front.sock
chmod-socket = 664
uid = udata
gid = www-data

; Tune these values according to your environment
processes = 5
cpu-affinity = 1

; Disable requests logging
disable-logging = True

; Disable write exception when nginx timed out before uwsgi response
disable-write-exception = true

; Avoid PyMongo fork issue
; http://stackoverflow.com/questions/34369866/running-uwsgi-with-mongoengine
lazy-apps = true

; Recycle workers (tune according to you environment)
max-requests = 4000
reload-on-as = 512
reload-on-rss = 192
limit-as = 1024
no-orphans = true
vacuum = true
reload-mercy = 8

Thanks a lot

@maudetes
Copy link
Contributor

maudetes commented Oct 20, 2022

Hello, it seems that uwsgi can't load the udata app indeed.
If it comes from the version used, you could try setting plugin = python37.
You should also make sure that your path does correspond to your configuration (virtualenv in /srv/udata/, etc.)

@liblzmasapue
Copy link
Author

liblzmasapue commented Nov 7, 2022

Hello,

We had no luck setting plugin=python37 or plugin=python in the udata-front.ini uwsgi conf file.

We have 'internal server error' landing page with plugin=python3 and plugin=python37, uwsgi service won't even start with plugin=python.

Fun thing, when setting plugin=python37, the uswgi log file says used python version is 3.6.9. So we followed this procedure to try to enable python3.7 with uwsgi but apparently with no luck.

The rest of the file seems fine (paths are correct).
Still, went looking for a udata.wsgi file (as mentionned in the udata-front.ini file) through the entire drive, no such file can be found, is that normal ?

Thanks again.

@maudetes
Copy link
Contributor

maudetes commented Nov 7, 2022

Still, went looking for a udata.wsgi file (as mentionned in the udata-front.ini file) through the entire drive, no such file can be found, is that normal ?

It is the WSGI entrypoint, it corresponds to the python module to import, wsgi in udata package: https://github.com/opendatateam/udata/blob/master/udata/wsgi.py.
My guess on ModuleNotFoundError: No module named 'udata' is that it probably doesn't use the correct virtualenv or udata isn't properly installed in this virtual env.

@liblzmasapue
Copy link
Author

Ok thanks we will investigate this way !

@liblzmasapue
Copy link
Author

liblzmasapue commented Nov 10, 2022

Ok we managed to make uwsgi use python 3.7 and it seems to find our Udata.
Here's the uwsgi log :

Thu Nov 10 11:17:31 2022 - worker 4 buried after 2 seconds
Thu Nov 10 11:17:31 2022 - worker 5 buried after 2 seconds
Thu Nov 10 11:17:31 2022 - goodbye to uWSGI.
Thu Nov 10 11:17:31 2022 - VACUUM: unix socket /run/uwsgi/app/udata-front/socket removed.
Thu Nov 10 11:17:31 2022 - VACUUM: unix socket /tmp/udata-front.sock removed.
Thu Nov 10 11:17:31 2022 - VACUUM: unix socket /tmp/udata-front-stats.sock (stats) removed.
Thu Nov 10 11:17:32 2022 - *** Starting uWSGI 2.0.15-debian (64bit) on [Thu Nov 10 11:17:32 2022] ***
Thu Nov 10 11:17:32 2022 - compiled with version: 7.5.0 on 26 August 2021 18:40:50
Thu Nov 10 11:17:32 2022 - os: Linux-4.15.0-194-generic #205-Ubuntu SMP Fri Sep 16 19:49:27 UTC 2022
Thu Nov 10 11:17:32 2022 - nodename: srv83data07
Thu Nov 10 11:17:32 2022 - machine: x86_64
Thu Nov 10 11:17:32 2022 - clock source: unix
Thu Nov 10 11:17:32 2022 - pcre jit disabled
Thu Nov 10 11:17:32 2022 - detected number of CPU cores: 1
Thu Nov 10 11:17:32 2022 - current working directory: /
Thu Nov 10 11:17:32 2022 - writing pidfile to /run/uwsgi/app/udata-front/pid
Thu Nov 10 11:17:32 2022 - detected binary path: /usr/bin/uwsgi-core
Thu Nov 10 11:17:32 2022 - dropping root privileges as early as possible
Thu Nov 10 11:17:32 2022 - setgid() to 33
Thu Nov 10 11:17:32 2022 - setuid() to 1001
Thu Nov 10 11:17:32 2022 - chdir() to /srv/udata
Thu Nov 10 11:17:32 2022 - your processes number limit is 15418
Thu Nov 10 11:17:32 2022 - limiting address space of processes...
Thu Nov 10 11:17:32 2022 - your process address space limit is 1073741824 bytes (1024 MB)
Thu Nov 10 11:17:32 2022 - your memory page size is 4096 bytes
Thu Nov 10 11:17:32 2022 - detected max file descriptor number: 1024
Thu Nov 10 11:17:32 2022 - lock engine: pthread robust mutexes
Thu Nov 10 11:17:32 2022 - thunder lock: disabled (you can enable it with --thunder-lock)
Thu Nov 10 11:17:32 2022 - uwsgi socket 0 bound to UNIX address /run/uwsgi/app/udata-front/socket fd 3
Thu Nov 10 11:17:32 2022 - uwsgi socket 1 bound to UNIX address /tmp/udata-front.sock fd 5
Thu Nov 10 11:17:32 2022 - dropping root privileges after socket binding
Thu Nov 10 11:17:32 2022 - Python version: 3.7.5 (default, Dec  9 2021, 17:04:37)  [GCC 8.4.0]
Thu Nov 10 11:17:32 2022 - PEP 405 virtualenv detected: /srv/udata
Thu Nov 10 11:17:32 2022 - Set PythonHome to /srv/udata
Thu Nov 10 11:17:32 2022 - *** Python threads support is disabled. You can enable it with --enable-threads ***
Thu Nov 10 11:17:32 2022 - Python main interpreter initialized at 0x55b9da4e2eb0
Thu Nov 10 11:17:32 2022 - dropping root privileges after plugin initialization
Thu Nov 10 11:17:32 2022 - your server socket listen backlog is limited to 100 connections
Thu Nov 10 11:17:32 2022 - your mercy for graceful operations on workers is 60 seconds
Thu Nov 10 11:17:32 2022 - mapped 436608 bytes (426 KB) for 5 cores
Thu Nov 10 11:17:32 2022 - *** Operational MODE: preforking ***
Thu Nov 10 11:17:32 2022 - added /srv/udata/bin/ to pythonpath.
Thu Nov 10 11:17:32 2022 - dropping root privileges after application loading
Thu Nov 10 11:17:32 2022 - *** uWSGI is running in multiple interpreter mode ***
Thu Nov 10 11:17:32 2022 - spawned uWSGI master process (pid: 72296)
Thu Nov 10 11:17:32 2022 - spawned uWSGI worker 1 (pid: 72301, cores: 1)
Thu Nov 10 11:17:32 2022 - spawned uWSGI worker 2 (pid: 72302, cores: 1)
Thu Nov 10 11:17:32 2022 - spawned uWSGI worker 3 (pid: 72303, cores: 1)
Thu Nov 10 11:17:32 2022 - spawned uWSGI worker 4 (pid: 72304, cores: 1)
Thu Nov 10 11:17:32 2022 - spawned uWSGI worker 5 (pid: 72305, cores: 1)
Thu Nov 10 11:17:32 2022 - *** Stats server enabled on /tmp/udata-front-stats.sock fd: 19 ***
Thu Nov 10 11:17:32 2022 - mapping worker 4 to CPUs: 0
Thu Nov 10 11:17:32 2022 - mapping worker 3 to CPUs: 0
Thu Nov 10 11:17:32 2022 - mapping worker 5 to CPUs: 0
Thu Nov 10 11:17:32 2022 - mapping worker 2 to CPUs: 0
Thu Nov 10 11:17:32 2022 - mapping worker 1 to CPUs: 0

Now, when accessing our server's landing page, we don't get Internal Server Error anymore, but we do get a 404 Not Found.

Uwsgi, Celery and Nginx were restarted.

Here's our nginx configuration file :

##
# nginx configuration for data.example.com
##

## uWSGI
upstream uwsgi-udata {
    ip_hash;
    server unix:///tmp/udata-front.sock;
    keepalive 32;
}

server {
    listen 80;
    server_name data.example.com **our_internal_ip_address**;

    access_log /var/log/nginx/data.example.com.access.log;
    error_log /var/log/nginx/data.example.com.error.log;

    client_max_body_size 0; # Disable max client body size

    root /srv/udata/public/;

    # Enable gzip compression
    gzip on;
    gzip_disable "msie6";
    gzip_min_length  1100;
    gzip_buffers  4 32k;
    gzip_types
        application/atom+xml
        application/javascript
        application/json
        application/rdf+xml
        application/rss+xml
        application/vnd.geo+json
        application/vnd.ms-fontobject
        application/x-font-ttf
        application/x-javascript
        application/xml
        font/opentype
        image/svg+xml
        image/x-icon
        text/css
        text/csv
        text/javascript
        text/plain
        text/xml;
    gzip_vary on;

    add_header Pragma public;
    add_header Cache-Control public;
    add_header Connection "keep-alive";

location / {

        try_files $uri @wsgi;

        location ~ /static/ {
            include /etc/nginx/static-common.conf;
        }

        location ~ /_themes/ {
            include /etc/nginx/static-common.conf;
        }

        location ~ /s/ {
            # Resources are stored separately
            alias /srv/udata/fs/;
            # Disable disk buffering for downloads
            proxy_max_temp_file_size 0;

            include /etc/nginx/static-common.conf;
        }
    }

    location @wsgi {
        uwsgi_pass uwsgi-udata;
        include uwsgi_params;

        proxy_redirect     off;
        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_set_header   X-Forwarded-Proto $scheme;
    }
}

And when accessing out server's IP address we get this error message.

image

sudo nginx -T says everything is OK.

@liblzmasapue
Copy link
Author

The nginx error log file shows this line after every try :

X.X.X.X - - [10/Nov/2022:11:44:32 +0100] "GET / HTTP/1.1" 404 232 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36"

@maudetes
Copy link
Contributor

For future users, could you specify how you fixed the issue to use the correct python 3.7 venv?

If you installed udata only, you don't have a frontend and should get a 404 on the home.
You can try accessing the API: /api/1/?
You can also add a frontend, ex using udata-front and activating this plugin.

@liblzmasapue
Copy link
Author

We managed to make uwsgi use python3.7 doing this :

$ sudo apt install \
python3.7-dev python3-distutils uwsgi uwsgi-src uuid-dev libcap-dev libpcre3-dev

Most packages were already installed.

We then ran the following commands to create a Python 3.7 plugin :

$ cd ~
$ export PYTHON=python3.7
$ uwsgi --build-plugin "/usr/src/uwsgi/plugins/python python37"

After that, we moved it to uwsgi plugins directory and changed rights :

$ sudo mv python37_plugin.so /usr/lib/uwsgi/plugins/python37_plugin.so
$ sudo chmod 644 /usr/lib/uwsgi/plugins/python37_plugin.so

Tested that out plugin was working :

$ uwsgi --plugin python37 -s :0

Then, in the uwsgi configuration file under /etc/uwsgi/apps-available/udata-front.ini, we changed the line "plugin" to :

plugin = python37

Restarted UWSGI, Celery, and Nginx, and after that, UWSGI logs showed 3.7.5 as the python version being used.

Right now, udata-front is installed, but only responding if we curl http://127.0.0.1:7000 from the server's command line after we started udata through a udata serve command.
curl http://10.x.x.124:7000 says connection refused. No firewall is enabled on the server at the moment.

@liblzmasapue
Copy link
Author

We added some variables to our udata.cfg file (which is being used, as we do get errors launching udata if we make syntax errors in this file)

# Optionally activate some installed plugins
PLUGINS = ('piwik','front')

# Optionally activate an installed theme
# THEME = 'my-theme'

# Define where resources are stored and exposed
FS_ROOT = '/srv/udata/fs'
FS_PREFIX = '/s'
THEME = 'gouvfr'
URLS_ALLOW_LOCAL = True
URLS_ALLOW_PRIVATE = True

@maudetes
Copy link
Contributor

I did not understand the current result of curl http://127.0.0.1:7000.
Did you try accessing the API: /api/1/?

In your udata.cfg, you have commented out the theme config.
By default, I would suggest to install the python package https://pypi.org/project/udata-front/ and use THEME = 'gouvfr' if you want to test with a frontend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants