I've recently got an Ubuntu 18 server and I'm a little confused to say the least.
First: If I run sudo service nginx start
or sudo systemctl start nginx
, everything appears to work. My site is loading, and both sudo service nginx status
and sudo systemctl status nginx
return an all clear message.
Now the issue: When I reboot my server, nginx
isn't automatically being started as the website is not being loaded. I tried sudo systemmctl enable nginx
and tried another reboot. Again, nginx
is not running as the website isn't loading.
In fact, if I reboot my server sudo reboot
and then sudo service nginx status
or sudo systemctl status nginx
I get an error message. Despite the error message, I can run sudo service nginx start
or sudo systemctl start nginx
and it'll all go back to working.
The error message I get is the following:
(venv) user@server:/data/project$ 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: failed (Result: exit-code) since Tue 2019-02-26 17:50:18 CET; 1min 6s ago
Docs: man:nginx(8)
Process: 830 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Feb 26 17:50:18 md3.tudelft.nl systemd[1]: Starting A high performance web server and a reverse proxy server...
Feb 26 17:50:18 md3.tudelft.nl nginx[830]: nginx: [emerg] open() "/data/project/uwsgi_params" failed (2: No such file or directory) in /etc/nginx/sites-enabled/paintingViewer.conf
Feb 26 17:50:18 md3.tudelft.nl nginx[830]: nginx: configuration file /etc/nginx/nginx.conf test failed
Feb 26 17:50:18 md3.tudelft.nl systemd[1]: nginx.service: Control process exited, code=exited status=1
Feb 26 17:50:18 md3.tudelft.nl systemd[1]: nginx.service: Failed with result 'exit-code'.
Feb 26 17:50:18 md3.tudelft.nl systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Well, that seems pretty simple: it can't find the uwsgi_params file. THe uwsgi_params file does exist though, and it is in the right location.
My nginx
.conf file:
# the upstream component nginx needs to connect to
upstream django {
server unix:///data/project/paintingViewer.sock; # for a file socket
# server 127.0.0.1:8001; # for a web port socket -> works if we use Djano's build in webserver.
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name server;
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /data/project/media; # your Django project's media files - amend as required
}
location /static {
alias /data/project/static; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /data/project/uwsgi_params; # the uwsgi_params file you installed
}
}
and the /data/project/uwsgi_params
file is:
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param REQUEST_SCHEME $scheme;
uwsgi_param HTTPS $https if_not_empty;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;
Now, there's a few things I don't understand:
1) How is it possible that nginx
works if I run the start
command, but that nginx
doesn't work on boot?
2) How can the status
read that nginx
can not find the uwsgi
file, while it works on a start
?
3) How can I get nginx
to run properly on a reboot?