Error on configuring gunicornNginx > Varnish > Gunicorn Error Too many RedirectionsHow to resolve the gunicorn critical worker timeout error?Gunicorn error: “Error opening file for reading: Permission denied”502 bad gateway: nginx & gunicornNginx+gunicorn 404Gunicorn intermittently returning HTTP502Gunicorn not responding — Ignored premature client disconnectionGunicorn Permission denied: '/dev/ttyUSB0'Nginx 404 error with gunicorn on django projectGunicorn with flask app returning 502 error
Warped chessboard
Gambler's Fallacy Dice
Vehemently against code formatting
Can 2 light bulbs of 120V in series be used on 230V AC?
How was the blinking terminal cursor invented?
Failing students when it might cause them economic ruin
How to choose the correct exposure for flower photography?
In Dutch history two people are referred to as "William III"; are there any more cases where this happens?
Germany rejected my entry to Schengen countries
Why is so much ransomware breakable?
Greek theta instead of lower case þ (Icelandic) in TexStudio
How can I prevent Bash expansion from passing files starting with "-" as argument?
What halachos of mourning apply to a grandchild for his grandparent's death?
Could a chemically propelled craft travel directly between Earth and Mars spaceports?
Does a windmilling propeller create more drag than a stopped propeller in an engine out scenario
Are there any crystals that are theoretically possible, but haven't yet been made?
Bash Read: Reading comma separated list, last element is missed
Does science define life as "beginning at conception"?
What is the backup for a glass cockpit, if a plane loses power to the displays/controls?
Isn't Kirchhoff's junction law a violation of conservation of charge?
In How Many Ways Can We Partition a Set Into Smaller Subsets So The Sum of the Numbers In Each Subset Is Equal?
Addressing an email
Parse a C++14 integer literal
Bash - Execute two commands and get exit status 1 if first fails
Error on configuring gunicorn
Nginx > Varnish > Gunicorn Error Too many RedirectionsHow to resolve the gunicorn critical worker timeout error?Gunicorn error: “Error opening file for reading: Permission denied”502 bad gateway: nginx & gunicornNginx+gunicorn 404Gunicorn intermittently returning HTTP502Gunicorn not responding — Ignored premature client disconnectionGunicorn Permission denied: '/dev/ttyUSB0'Nginx 404 error with gunicorn on django projectGunicorn with flask app returning 502 error
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have been following this tutorial to deploy my django project on Digital Ocean. I am trying to configure gunicorn.
My project structure looks similar to this:
On my settings.py
I use DEBUG=False
I create the gunicorn.socket and gunicorn.service.
/etc/systemd/system/gunicorn.socket
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target
/etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=someuser
Group=www-data
WorkingDirectory=/home/someuser/myproject
ExecStart=/home/someuser/myproject/myprojectenv/bin/gunicorn
--access-logfile -
--workers 3
--bind unix:/run/gunicorn.sock
Myproject.wsgi:application
[Install]
WantedBy=multi-user.target
I start and enable the Gunicorn socket:
sudo systemctl start gunicorn.socket
sudo systemctl enable gunicorn.socket
Check the status of the process to find out whether it was able to start:
sudo systemctl status gunicorn.socket
This is what I get and then it returns to the command line.
Failed to dump process list, ignoring: No such file or directory
● gunicorn.socket - gunicorn socket
Loaded: loaded (/etc/systemd/system/gunicorn.socket; enabled; vendor preset: enabled)
Active: active (listening) since Sat 2019-05-04 23:12:03 UTC; 13s ago
Listen: /run/gunicorn.sock (Stream)
CGroup: /system.slice/gunicorn.socket
May 04 23:12:03 myproject systemd[1]: Listening on gunicorn socket.
Next, I check for the existence of the gunicorn.sock file within the /run directory:
file /run/gunicorn.sock
/run/gunicorn.sock: socket
It seems that a file or directory doesn't exist, but it doesn't provide any more details. The gunicorn.sock seems to exist.
I have decided to go through with the whole tutorial and see what happens:
This is the gunicorn socket's log:
$ sudo journalctl -u gunicorn.socket
-- Logs begin at Fri 2019-05-03 21:38:51 UTC, end at Tue 2019-05-07 20:05:36 UTC. --
May 07 20:04:42 myproject systemd[1]: Listening on gunicorn socket.
Testing Socket Activation
$ sudo systemctl status gunicorn
gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; disabled; vendor preset: enabled)
Active: inactive (dead)
To test the socket activation mechanism, we can send a connection to the socket through curl by typing:
$ curl --unix-socket /run/gunicorn.sock localhost
running this, going to myip:8000, the tutoral says that I should see the HTML output from my application in the terminal which does not happen.
After a while of nothing happening, I get in the terminal:
<h1>Bad Request (400)</h1>
To verify that the Gunicorn service is running:
$ sudo systemctl status gunicorn
gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2019-05-07 20:06:15 UTC; 1min 5s ago
Main PID: 1884 (gunicorn)
Tasks: 4 (limit: 1152)
CGroup: /system.slice/gunicorn.service
1884 /home/someuser/myproject/myprojectenv/bin/python3 /home/someuser/myproject/myprojectenv/bin/gunicorn --access-
1915 /home/someuser/myproject/myprojectenv/bin/python3 /home/someuser/myproject/myprojectenv/bin/gunicorn --access-
1916 /home/someuser/myproject/myprojectenv/bin/python3 /home/someuser/myproject/myprojectenv/bin/gunicorn --access-
1917 /home/someuser/myproject/myprojectenv/bin/python3 /home/someuser/myproject/myprojectenv/bin/gunicorn --access-
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1904] [INFO] Booting worker with pid: 1904
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1905] [INFO] Booting worker with pid: 1905
May 07 20:06:46 myproject gunicorn[1884]: [2019-05-07 20:06:46 +0000] [1884] [CRITICAL] WORKER TIMEOUT (pid:1902)
May 07 20:06:46 myproject gunicorn[1884]: [2019-05-07 20:06:46 +0000] [1884] [CRITICAL] WORKER TIMEOUT (pid:1904)
May 07 20:06:46 myproject gunicorn[1884]: [2019-05-07 20:06:46 +0000] [1884] [CRITICAL] WORKER TIMEOUT (pid:1905)
May 07 20:06:47 myproject gunicorn[1884]: [2019-05-07 20:06:47 +0000] [1915] [INFO] Booting worker with pid: 1915
May 07 20:06:47 myproject gunicorn[1884]: [2019-05-07 20:06:47 +0000] [1916] [INFO] Booting worker with pid: 1916
May 07 20:06:47 myproject gunicorn[1884]: [2019-05-07 20:06:47 +0000] [1917] [INFO] Booting worker with pid: 1917
May 07 20:07:02 myproject gunicorn[1884]: - - [07/May/2019:20:07:02 +0000] "GET / HTTP/1.1" 400 26 "-" "curl/7.58.0"
May 07 20:07:10 myproject gunicorn[1884]: - - [07/May/2019:20:07:10 +0000] "GET / HTTP/1.1" 400 26 "-" "curl/7.58.0"
Checking the gunicorn logs:
$ sudo journalctl -u gunicorn
-- Logs begin at Fri 2019-05-03 21:38:51 UTC, end at Tue 2019-05-07 20:07:58 UTC. --
May 07 20:06:15 myproject systemd[1]: Started gunicorn daemon.
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1884] [INFO] Starting gunicorn 19.9.0
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1884] [INFO] Listening at: unix:/run/gunicorn.sock (1884)
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1884] [INFO] Using worker: sync
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1902] [INFO] Booting worker with pid: 1902
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1904] [INFO] Booting worker with pid: 1904
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1905] [INFO] Booting worker with pid: 1905
May 07 20:06:46 myproject gunicorn[1884]: [2019-05-07 20:06:46 +0000] [1884] [CRITICAL] WORKER TIMEOUT (pid:1902)
May 07 20:06:46 myproject gunicorn[1884]: [2019-05-07 20:06:46 +0000] [1884] [CRITICAL] WORKER TIMEOUT (pid:1904)
May 07 20:06:46 myproject gunicorn[1884]: [2019-05-07 20:06:46 +0000] [1884] [CRITICAL] WORKER TIMEOUT (pid:1905)
May 07 20:06:47 myproject gunicorn[1884]: [2019-05-07 20:06:47 +0000] [1915] [INFO] Booting worker with pid: 1915
May 07 20:06:47 myproject gunicorn[1884]: [2019-05-07 20:06:47 +0000] [1916] [INFO] Booting worker with pid: 1916
May 07 20:06:47 myproject gunicorn[1884]: [2019-05-07 20:06:47 +0000] [1917] [INFO] Booting worker with pid: 1917
May 07 20:07:02 myproject gunicorn[1884]: - - [07/May/2019:20:07:02 +0000] "GET / HTTP/1.1" 400 26 "-" "curl/7.58.0"
May 07 20:07:10 myproject gunicorn[1884]: - - [07/May/2019:20:07:10 +0000] "GET / HTTP/1.1" 400 26 "-" "curl/7.58.0"
After that it is the configuration of nginx:
$ sudo nano /etc/nginx/sites-available/Myproject
server
listen 80;
server_name xxx.xxx.xxx.xxx;
location = /favicon.ico access_log off; log_not_found off;
location /staticfiles/
root /home/someuser/myproject ;
location /
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
Enable the file by linking it to the sites-enabled directory:
$ sudo ln -s /etc/nginx/sites-available/Myproject /etc/nginx/sites-enabled
Test your Nginx configuration for syntax errors by typing:
$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
If no errors are reported, go ahead and restart Nginx by typing:
$ sudo systemctl restart nginx
Finally, we need to open up our firewall to normal traffic on port 80. Since we no longer need access to the development server, we can remove the rule to open port 8000 as well:
$ sudo ufw delete allow 8000
Rule deleted
Rule deleted (v6)
$ sudo ufw allow 'Nginx Full'
Rule added
Rule added (v6)
You should now be able to go to your server's domain or IP address to view your application.
Going to xxx.xxx.xxx.xxx:8000
, I get that this site can't be reached, took too long to respond.
During all this in my settings.py
, I have this:
ALLOWED_HOSTS = ["xxx.xxx.xxx.xxx"] # my droplet's ip
I am familiar with Python but not with servers and deploying so I am at a loss here.
I have successfully followed the similar tutorial for Ubuntu 16.04 a few months ago, but now I keep hitting issues.
Any weird characters seem to appear because I copy paste the output from the PyCharm terminal.
gunicorn
add a comment |
I have been following this tutorial to deploy my django project on Digital Ocean. I am trying to configure gunicorn.
My project structure looks similar to this:
On my settings.py
I use DEBUG=False
I create the gunicorn.socket and gunicorn.service.
/etc/systemd/system/gunicorn.socket
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target
/etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=someuser
Group=www-data
WorkingDirectory=/home/someuser/myproject
ExecStart=/home/someuser/myproject/myprojectenv/bin/gunicorn
--access-logfile -
--workers 3
--bind unix:/run/gunicorn.sock
Myproject.wsgi:application
[Install]
WantedBy=multi-user.target
I start and enable the Gunicorn socket:
sudo systemctl start gunicorn.socket
sudo systemctl enable gunicorn.socket
Check the status of the process to find out whether it was able to start:
sudo systemctl status gunicorn.socket
This is what I get and then it returns to the command line.
Failed to dump process list, ignoring: No such file or directory
● gunicorn.socket - gunicorn socket
Loaded: loaded (/etc/systemd/system/gunicorn.socket; enabled; vendor preset: enabled)
Active: active (listening) since Sat 2019-05-04 23:12:03 UTC; 13s ago
Listen: /run/gunicorn.sock (Stream)
CGroup: /system.slice/gunicorn.socket
May 04 23:12:03 myproject systemd[1]: Listening on gunicorn socket.
Next, I check for the existence of the gunicorn.sock file within the /run directory:
file /run/gunicorn.sock
/run/gunicorn.sock: socket
It seems that a file or directory doesn't exist, but it doesn't provide any more details. The gunicorn.sock seems to exist.
I have decided to go through with the whole tutorial and see what happens:
This is the gunicorn socket's log:
$ sudo journalctl -u gunicorn.socket
-- Logs begin at Fri 2019-05-03 21:38:51 UTC, end at Tue 2019-05-07 20:05:36 UTC. --
May 07 20:04:42 myproject systemd[1]: Listening on gunicorn socket.
Testing Socket Activation
$ sudo systemctl status gunicorn
gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; disabled; vendor preset: enabled)
Active: inactive (dead)
To test the socket activation mechanism, we can send a connection to the socket through curl by typing:
$ curl --unix-socket /run/gunicorn.sock localhost
running this, going to myip:8000, the tutoral says that I should see the HTML output from my application in the terminal which does not happen.
After a while of nothing happening, I get in the terminal:
<h1>Bad Request (400)</h1>
To verify that the Gunicorn service is running:
$ sudo systemctl status gunicorn
gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2019-05-07 20:06:15 UTC; 1min 5s ago
Main PID: 1884 (gunicorn)
Tasks: 4 (limit: 1152)
CGroup: /system.slice/gunicorn.service
1884 /home/someuser/myproject/myprojectenv/bin/python3 /home/someuser/myproject/myprojectenv/bin/gunicorn --access-
1915 /home/someuser/myproject/myprojectenv/bin/python3 /home/someuser/myproject/myprojectenv/bin/gunicorn --access-
1916 /home/someuser/myproject/myprojectenv/bin/python3 /home/someuser/myproject/myprojectenv/bin/gunicorn --access-
1917 /home/someuser/myproject/myprojectenv/bin/python3 /home/someuser/myproject/myprojectenv/bin/gunicorn --access-
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1904] [INFO] Booting worker with pid: 1904
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1905] [INFO] Booting worker with pid: 1905
May 07 20:06:46 myproject gunicorn[1884]: [2019-05-07 20:06:46 +0000] [1884] [CRITICAL] WORKER TIMEOUT (pid:1902)
May 07 20:06:46 myproject gunicorn[1884]: [2019-05-07 20:06:46 +0000] [1884] [CRITICAL] WORKER TIMEOUT (pid:1904)
May 07 20:06:46 myproject gunicorn[1884]: [2019-05-07 20:06:46 +0000] [1884] [CRITICAL] WORKER TIMEOUT (pid:1905)
May 07 20:06:47 myproject gunicorn[1884]: [2019-05-07 20:06:47 +0000] [1915] [INFO] Booting worker with pid: 1915
May 07 20:06:47 myproject gunicorn[1884]: [2019-05-07 20:06:47 +0000] [1916] [INFO] Booting worker with pid: 1916
May 07 20:06:47 myproject gunicorn[1884]: [2019-05-07 20:06:47 +0000] [1917] [INFO] Booting worker with pid: 1917
May 07 20:07:02 myproject gunicorn[1884]: - - [07/May/2019:20:07:02 +0000] "GET / HTTP/1.1" 400 26 "-" "curl/7.58.0"
May 07 20:07:10 myproject gunicorn[1884]: - - [07/May/2019:20:07:10 +0000] "GET / HTTP/1.1" 400 26 "-" "curl/7.58.0"
Checking the gunicorn logs:
$ sudo journalctl -u gunicorn
-- Logs begin at Fri 2019-05-03 21:38:51 UTC, end at Tue 2019-05-07 20:07:58 UTC. --
May 07 20:06:15 myproject systemd[1]: Started gunicorn daemon.
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1884] [INFO] Starting gunicorn 19.9.0
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1884] [INFO] Listening at: unix:/run/gunicorn.sock (1884)
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1884] [INFO] Using worker: sync
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1902] [INFO] Booting worker with pid: 1902
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1904] [INFO] Booting worker with pid: 1904
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1905] [INFO] Booting worker with pid: 1905
May 07 20:06:46 myproject gunicorn[1884]: [2019-05-07 20:06:46 +0000] [1884] [CRITICAL] WORKER TIMEOUT (pid:1902)
May 07 20:06:46 myproject gunicorn[1884]: [2019-05-07 20:06:46 +0000] [1884] [CRITICAL] WORKER TIMEOUT (pid:1904)
May 07 20:06:46 myproject gunicorn[1884]: [2019-05-07 20:06:46 +0000] [1884] [CRITICAL] WORKER TIMEOUT (pid:1905)
May 07 20:06:47 myproject gunicorn[1884]: [2019-05-07 20:06:47 +0000] [1915] [INFO] Booting worker with pid: 1915
May 07 20:06:47 myproject gunicorn[1884]: [2019-05-07 20:06:47 +0000] [1916] [INFO] Booting worker with pid: 1916
May 07 20:06:47 myproject gunicorn[1884]: [2019-05-07 20:06:47 +0000] [1917] [INFO] Booting worker with pid: 1917
May 07 20:07:02 myproject gunicorn[1884]: - - [07/May/2019:20:07:02 +0000] "GET / HTTP/1.1" 400 26 "-" "curl/7.58.0"
May 07 20:07:10 myproject gunicorn[1884]: - - [07/May/2019:20:07:10 +0000] "GET / HTTP/1.1" 400 26 "-" "curl/7.58.0"
After that it is the configuration of nginx:
$ sudo nano /etc/nginx/sites-available/Myproject
server
listen 80;
server_name xxx.xxx.xxx.xxx;
location = /favicon.ico access_log off; log_not_found off;
location /staticfiles/
root /home/someuser/myproject ;
location /
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
Enable the file by linking it to the sites-enabled directory:
$ sudo ln -s /etc/nginx/sites-available/Myproject /etc/nginx/sites-enabled
Test your Nginx configuration for syntax errors by typing:
$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
If no errors are reported, go ahead and restart Nginx by typing:
$ sudo systemctl restart nginx
Finally, we need to open up our firewall to normal traffic on port 80. Since we no longer need access to the development server, we can remove the rule to open port 8000 as well:
$ sudo ufw delete allow 8000
Rule deleted
Rule deleted (v6)
$ sudo ufw allow 'Nginx Full'
Rule added
Rule added (v6)
You should now be able to go to your server's domain or IP address to view your application.
Going to xxx.xxx.xxx.xxx:8000
, I get that this site can't be reached, took too long to respond.
During all this in my settings.py
, I have this:
ALLOWED_HOSTS = ["xxx.xxx.xxx.xxx"] # my droplet's ip
I am familiar with Python but not with servers and deploying so I am at a loss here.
I have successfully followed the similar tutorial for Ubuntu 16.04 a few months ago, but now I keep hitting issues.
Any weird characters seem to appear because I copy paste the output from the PyCharm terminal.
gunicorn
Hm, I think something went wrong with your paste, I could not see the error message the first time because of some strange characters. Probably your ssh connection is not using UTF-8 for some reason. I think it's fixed now, and I can see the error.
– Michael Hampton♦
May 7 at 3:30
A quick trip through Google suggests that nobody else knows what it means either, but that it's entirely harmless. You should continue setting up your service.
– Michael Hampton♦
May 7 at 3:40
@MichaelHampton Ok, thakns. I will keep going with the tutorial and report any other issues, if that's ok.
– GiannisIordanou
May 7 at 3:56
@MichaelHampton I have updated my question with the commands I run and the output I get.
– GiannisIordanou
May 7 at 20:42
Going to xxx.xxx.xxx.xxx, the site is being served correctly, apart of the static files. I suppose there is an issue with the proper directories.
– GiannisIordanou
May 7 at 21:17
add a comment |
I have been following this tutorial to deploy my django project on Digital Ocean. I am trying to configure gunicorn.
My project structure looks similar to this:
On my settings.py
I use DEBUG=False
I create the gunicorn.socket and gunicorn.service.
/etc/systemd/system/gunicorn.socket
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target
/etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=someuser
Group=www-data
WorkingDirectory=/home/someuser/myproject
ExecStart=/home/someuser/myproject/myprojectenv/bin/gunicorn
--access-logfile -
--workers 3
--bind unix:/run/gunicorn.sock
Myproject.wsgi:application
[Install]
WantedBy=multi-user.target
I start and enable the Gunicorn socket:
sudo systemctl start gunicorn.socket
sudo systemctl enable gunicorn.socket
Check the status of the process to find out whether it was able to start:
sudo systemctl status gunicorn.socket
This is what I get and then it returns to the command line.
Failed to dump process list, ignoring: No such file or directory
● gunicorn.socket - gunicorn socket
Loaded: loaded (/etc/systemd/system/gunicorn.socket; enabled; vendor preset: enabled)
Active: active (listening) since Sat 2019-05-04 23:12:03 UTC; 13s ago
Listen: /run/gunicorn.sock (Stream)
CGroup: /system.slice/gunicorn.socket
May 04 23:12:03 myproject systemd[1]: Listening on gunicorn socket.
Next, I check for the existence of the gunicorn.sock file within the /run directory:
file /run/gunicorn.sock
/run/gunicorn.sock: socket
It seems that a file or directory doesn't exist, but it doesn't provide any more details. The gunicorn.sock seems to exist.
I have decided to go through with the whole tutorial and see what happens:
This is the gunicorn socket's log:
$ sudo journalctl -u gunicorn.socket
-- Logs begin at Fri 2019-05-03 21:38:51 UTC, end at Tue 2019-05-07 20:05:36 UTC. --
May 07 20:04:42 myproject systemd[1]: Listening on gunicorn socket.
Testing Socket Activation
$ sudo systemctl status gunicorn
gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; disabled; vendor preset: enabled)
Active: inactive (dead)
To test the socket activation mechanism, we can send a connection to the socket through curl by typing:
$ curl --unix-socket /run/gunicorn.sock localhost
running this, going to myip:8000, the tutoral says that I should see the HTML output from my application in the terminal which does not happen.
After a while of nothing happening, I get in the terminal:
<h1>Bad Request (400)</h1>
To verify that the Gunicorn service is running:
$ sudo systemctl status gunicorn
gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2019-05-07 20:06:15 UTC; 1min 5s ago
Main PID: 1884 (gunicorn)
Tasks: 4 (limit: 1152)
CGroup: /system.slice/gunicorn.service
1884 /home/someuser/myproject/myprojectenv/bin/python3 /home/someuser/myproject/myprojectenv/bin/gunicorn --access-
1915 /home/someuser/myproject/myprojectenv/bin/python3 /home/someuser/myproject/myprojectenv/bin/gunicorn --access-
1916 /home/someuser/myproject/myprojectenv/bin/python3 /home/someuser/myproject/myprojectenv/bin/gunicorn --access-
1917 /home/someuser/myproject/myprojectenv/bin/python3 /home/someuser/myproject/myprojectenv/bin/gunicorn --access-
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1904] [INFO] Booting worker with pid: 1904
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1905] [INFO] Booting worker with pid: 1905
May 07 20:06:46 myproject gunicorn[1884]: [2019-05-07 20:06:46 +0000] [1884] [CRITICAL] WORKER TIMEOUT (pid:1902)
May 07 20:06:46 myproject gunicorn[1884]: [2019-05-07 20:06:46 +0000] [1884] [CRITICAL] WORKER TIMEOUT (pid:1904)
May 07 20:06:46 myproject gunicorn[1884]: [2019-05-07 20:06:46 +0000] [1884] [CRITICAL] WORKER TIMEOUT (pid:1905)
May 07 20:06:47 myproject gunicorn[1884]: [2019-05-07 20:06:47 +0000] [1915] [INFO] Booting worker with pid: 1915
May 07 20:06:47 myproject gunicorn[1884]: [2019-05-07 20:06:47 +0000] [1916] [INFO] Booting worker with pid: 1916
May 07 20:06:47 myproject gunicorn[1884]: [2019-05-07 20:06:47 +0000] [1917] [INFO] Booting worker with pid: 1917
May 07 20:07:02 myproject gunicorn[1884]: - - [07/May/2019:20:07:02 +0000] "GET / HTTP/1.1" 400 26 "-" "curl/7.58.0"
May 07 20:07:10 myproject gunicorn[1884]: - - [07/May/2019:20:07:10 +0000] "GET / HTTP/1.1" 400 26 "-" "curl/7.58.0"
Checking the gunicorn logs:
$ sudo journalctl -u gunicorn
-- Logs begin at Fri 2019-05-03 21:38:51 UTC, end at Tue 2019-05-07 20:07:58 UTC. --
May 07 20:06:15 myproject systemd[1]: Started gunicorn daemon.
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1884] [INFO] Starting gunicorn 19.9.0
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1884] [INFO] Listening at: unix:/run/gunicorn.sock (1884)
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1884] [INFO] Using worker: sync
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1902] [INFO] Booting worker with pid: 1902
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1904] [INFO] Booting worker with pid: 1904
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1905] [INFO] Booting worker with pid: 1905
May 07 20:06:46 myproject gunicorn[1884]: [2019-05-07 20:06:46 +0000] [1884] [CRITICAL] WORKER TIMEOUT (pid:1902)
May 07 20:06:46 myproject gunicorn[1884]: [2019-05-07 20:06:46 +0000] [1884] [CRITICAL] WORKER TIMEOUT (pid:1904)
May 07 20:06:46 myproject gunicorn[1884]: [2019-05-07 20:06:46 +0000] [1884] [CRITICAL] WORKER TIMEOUT (pid:1905)
May 07 20:06:47 myproject gunicorn[1884]: [2019-05-07 20:06:47 +0000] [1915] [INFO] Booting worker with pid: 1915
May 07 20:06:47 myproject gunicorn[1884]: [2019-05-07 20:06:47 +0000] [1916] [INFO] Booting worker with pid: 1916
May 07 20:06:47 myproject gunicorn[1884]: [2019-05-07 20:06:47 +0000] [1917] [INFO] Booting worker with pid: 1917
May 07 20:07:02 myproject gunicorn[1884]: - - [07/May/2019:20:07:02 +0000] "GET / HTTP/1.1" 400 26 "-" "curl/7.58.0"
May 07 20:07:10 myproject gunicorn[1884]: - - [07/May/2019:20:07:10 +0000] "GET / HTTP/1.1" 400 26 "-" "curl/7.58.0"
After that it is the configuration of nginx:
$ sudo nano /etc/nginx/sites-available/Myproject
server
listen 80;
server_name xxx.xxx.xxx.xxx;
location = /favicon.ico access_log off; log_not_found off;
location /staticfiles/
root /home/someuser/myproject ;
location /
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
Enable the file by linking it to the sites-enabled directory:
$ sudo ln -s /etc/nginx/sites-available/Myproject /etc/nginx/sites-enabled
Test your Nginx configuration for syntax errors by typing:
$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
If no errors are reported, go ahead and restart Nginx by typing:
$ sudo systemctl restart nginx
Finally, we need to open up our firewall to normal traffic on port 80. Since we no longer need access to the development server, we can remove the rule to open port 8000 as well:
$ sudo ufw delete allow 8000
Rule deleted
Rule deleted (v6)
$ sudo ufw allow 'Nginx Full'
Rule added
Rule added (v6)
You should now be able to go to your server's domain or IP address to view your application.
Going to xxx.xxx.xxx.xxx:8000
, I get that this site can't be reached, took too long to respond.
During all this in my settings.py
, I have this:
ALLOWED_HOSTS = ["xxx.xxx.xxx.xxx"] # my droplet's ip
I am familiar with Python but not with servers and deploying so I am at a loss here.
I have successfully followed the similar tutorial for Ubuntu 16.04 a few months ago, but now I keep hitting issues.
Any weird characters seem to appear because I copy paste the output from the PyCharm terminal.
gunicorn
I have been following this tutorial to deploy my django project on Digital Ocean. I am trying to configure gunicorn.
My project structure looks similar to this:
On my settings.py
I use DEBUG=False
I create the gunicorn.socket and gunicorn.service.
/etc/systemd/system/gunicorn.socket
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target
/etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=someuser
Group=www-data
WorkingDirectory=/home/someuser/myproject
ExecStart=/home/someuser/myproject/myprojectenv/bin/gunicorn
--access-logfile -
--workers 3
--bind unix:/run/gunicorn.sock
Myproject.wsgi:application
[Install]
WantedBy=multi-user.target
I start and enable the Gunicorn socket:
sudo systemctl start gunicorn.socket
sudo systemctl enable gunicorn.socket
Check the status of the process to find out whether it was able to start:
sudo systemctl status gunicorn.socket
This is what I get and then it returns to the command line.
Failed to dump process list, ignoring: No such file or directory
● gunicorn.socket - gunicorn socket
Loaded: loaded (/etc/systemd/system/gunicorn.socket; enabled; vendor preset: enabled)
Active: active (listening) since Sat 2019-05-04 23:12:03 UTC; 13s ago
Listen: /run/gunicorn.sock (Stream)
CGroup: /system.slice/gunicorn.socket
May 04 23:12:03 myproject systemd[1]: Listening on gunicorn socket.
Next, I check for the existence of the gunicorn.sock file within the /run directory:
file /run/gunicorn.sock
/run/gunicorn.sock: socket
It seems that a file or directory doesn't exist, but it doesn't provide any more details. The gunicorn.sock seems to exist.
I have decided to go through with the whole tutorial and see what happens:
This is the gunicorn socket's log:
$ sudo journalctl -u gunicorn.socket
-- Logs begin at Fri 2019-05-03 21:38:51 UTC, end at Tue 2019-05-07 20:05:36 UTC. --
May 07 20:04:42 myproject systemd[1]: Listening on gunicorn socket.
Testing Socket Activation
$ sudo systemctl status gunicorn
gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; disabled; vendor preset: enabled)
Active: inactive (dead)
To test the socket activation mechanism, we can send a connection to the socket through curl by typing:
$ curl --unix-socket /run/gunicorn.sock localhost
running this, going to myip:8000, the tutoral says that I should see the HTML output from my application in the terminal which does not happen.
After a while of nothing happening, I get in the terminal:
<h1>Bad Request (400)</h1>
To verify that the Gunicorn service is running:
$ sudo systemctl status gunicorn
gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2019-05-07 20:06:15 UTC; 1min 5s ago
Main PID: 1884 (gunicorn)
Tasks: 4 (limit: 1152)
CGroup: /system.slice/gunicorn.service
1884 /home/someuser/myproject/myprojectenv/bin/python3 /home/someuser/myproject/myprojectenv/bin/gunicorn --access-
1915 /home/someuser/myproject/myprojectenv/bin/python3 /home/someuser/myproject/myprojectenv/bin/gunicorn --access-
1916 /home/someuser/myproject/myprojectenv/bin/python3 /home/someuser/myproject/myprojectenv/bin/gunicorn --access-
1917 /home/someuser/myproject/myprojectenv/bin/python3 /home/someuser/myproject/myprojectenv/bin/gunicorn --access-
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1904] [INFO] Booting worker with pid: 1904
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1905] [INFO] Booting worker with pid: 1905
May 07 20:06:46 myproject gunicorn[1884]: [2019-05-07 20:06:46 +0000] [1884] [CRITICAL] WORKER TIMEOUT (pid:1902)
May 07 20:06:46 myproject gunicorn[1884]: [2019-05-07 20:06:46 +0000] [1884] [CRITICAL] WORKER TIMEOUT (pid:1904)
May 07 20:06:46 myproject gunicorn[1884]: [2019-05-07 20:06:46 +0000] [1884] [CRITICAL] WORKER TIMEOUT (pid:1905)
May 07 20:06:47 myproject gunicorn[1884]: [2019-05-07 20:06:47 +0000] [1915] [INFO] Booting worker with pid: 1915
May 07 20:06:47 myproject gunicorn[1884]: [2019-05-07 20:06:47 +0000] [1916] [INFO] Booting worker with pid: 1916
May 07 20:06:47 myproject gunicorn[1884]: [2019-05-07 20:06:47 +0000] [1917] [INFO] Booting worker with pid: 1917
May 07 20:07:02 myproject gunicorn[1884]: - - [07/May/2019:20:07:02 +0000] "GET / HTTP/1.1" 400 26 "-" "curl/7.58.0"
May 07 20:07:10 myproject gunicorn[1884]: - - [07/May/2019:20:07:10 +0000] "GET / HTTP/1.1" 400 26 "-" "curl/7.58.0"
Checking the gunicorn logs:
$ sudo journalctl -u gunicorn
-- Logs begin at Fri 2019-05-03 21:38:51 UTC, end at Tue 2019-05-07 20:07:58 UTC. --
May 07 20:06:15 myproject systemd[1]: Started gunicorn daemon.
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1884] [INFO] Starting gunicorn 19.9.0
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1884] [INFO] Listening at: unix:/run/gunicorn.sock (1884)
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1884] [INFO] Using worker: sync
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1902] [INFO] Booting worker with pid: 1902
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1904] [INFO] Booting worker with pid: 1904
May 07 20:06:16 myproject gunicorn[1884]: [2019-05-07 20:06:16 +0000] [1905] [INFO] Booting worker with pid: 1905
May 07 20:06:46 myproject gunicorn[1884]: [2019-05-07 20:06:46 +0000] [1884] [CRITICAL] WORKER TIMEOUT (pid:1902)
May 07 20:06:46 myproject gunicorn[1884]: [2019-05-07 20:06:46 +0000] [1884] [CRITICAL] WORKER TIMEOUT (pid:1904)
May 07 20:06:46 myproject gunicorn[1884]: [2019-05-07 20:06:46 +0000] [1884] [CRITICAL] WORKER TIMEOUT (pid:1905)
May 07 20:06:47 myproject gunicorn[1884]: [2019-05-07 20:06:47 +0000] [1915] [INFO] Booting worker with pid: 1915
May 07 20:06:47 myproject gunicorn[1884]: [2019-05-07 20:06:47 +0000] [1916] [INFO] Booting worker with pid: 1916
May 07 20:06:47 myproject gunicorn[1884]: [2019-05-07 20:06:47 +0000] [1917] [INFO] Booting worker with pid: 1917
May 07 20:07:02 myproject gunicorn[1884]: - - [07/May/2019:20:07:02 +0000] "GET / HTTP/1.1" 400 26 "-" "curl/7.58.0"
May 07 20:07:10 myproject gunicorn[1884]: - - [07/May/2019:20:07:10 +0000] "GET / HTTP/1.1" 400 26 "-" "curl/7.58.0"
After that it is the configuration of nginx:
$ sudo nano /etc/nginx/sites-available/Myproject
server
listen 80;
server_name xxx.xxx.xxx.xxx;
location = /favicon.ico access_log off; log_not_found off;
location /staticfiles/
root /home/someuser/myproject ;
location /
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
Enable the file by linking it to the sites-enabled directory:
$ sudo ln -s /etc/nginx/sites-available/Myproject /etc/nginx/sites-enabled
Test your Nginx configuration for syntax errors by typing:
$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
If no errors are reported, go ahead and restart Nginx by typing:
$ sudo systemctl restart nginx
Finally, we need to open up our firewall to normal traffic on port 80. Since we no longer need access to the development server, we can remove the rule to open port 8000 as well:
$ sudo ufw delete allow 8000
Rule deleted
Rule deleted (v6)
$ sudo ufw allow 'Nginx Full'
Rule added
Rule added (v6)
You should now be able to go to your server's domain or IP address to view your application.
Going to xxx.xxx.xxx.xxx:8000
, I get that this site can't be reached, took too long to respond.
During all this in my settings.py
, I have this:
ALLOWED_HOSTS = ["xxx.xxx.xxx.xxx"] # my droplet's ip
I am familiar with Python but not with servers and deploying so I am at a loss here.
I have successfully followed the similar tutorial for Ubuntu 16.04 a few months ago, but now I keep hitting issues.
Any weird characters seem to appear because I copy paste the output from the PyCharm terminal.
gunicorn
gunicorn
edited May 7 at 20:37
GiannisIordanou
asked May 6 at 21:16
GiannisIordanouGiannisIordanou
1041
1041
Hm, I think something went wrong with your paste, I could not see the error message the first time because of some strange characters. Probably your ssh connection is not using UTF-8 for some reason. I think it's fixed now, and I can see the error.
– Michael Hampton♦
May 7 at 3:30
A quick trip through Google suggests that nobody else knows what it means either, but that it's entirely harmless. You should continue setting up your service.
– Michael Hampton♦
May 7 at 3:40
@MichaelHampton Ok, thakns. I will keep going with the tutorial and report any other issues, if that's ok.
– GiannisIordanou
May 7 at 3:56
@MichaelHampton I have updated my question with the commands I run and the output I get.
– GiannisIordanou
May 7 at 20:42
Going to xxx.xxx.xxx.xxx, the site is being served correctly, apart of the static files. I suppose there is an issue with the proper directories.
– GiannisIordanou
May 7 at 21:17
add a comment |
Hm, I think something went wrong with your paste, I could not see the error message the first time because of some strange characters. Probably your ssh connection is not using UTF-8 for some reason. I think it's fixed now, and I can see the error.
– Michael Hampton♦
May 7 at 3:30
A quick trip through Google suggests that nobody else knows what it means either, but that it's entirely harmless. You should continue setting up your service.
– Michael Hampton♦
May 7 at 3:40
@MichaelHampton Ok, thakns. I will keep going with the tutorial and report any other issues, if that's ok.
– GiannisIordanou
May 7 at 3:56
@MichaelHampton I have updated my question with the commands I run and the output I get.
– GiannisIordanou
May 7 at 20:42
Going to xxx.xxx.xxx.xxx, the site is being served correctly, apart of the static files. I suppose there is an issue with the proper directories.
– GiannisIordanou
May 7 at 21:17
Hm, I think something went wrong with your paste, I could not see the error message the first time because of some strange characters. Probably your ssh connection is not using UTF-8 for some reason. I think it's fixed now, and I can see the error.
– Michael Hampton♦
May 7 at 3:30
Hm, I think something went wrong with your paste, I could not see the error message the first time because of some strange characters. Probably your ssh connection is not using UTF-8 for some reason. I think it's fixed now, and I can see the error.
– Michael Hampton♦
May 7 at 3:30
A quick trip through Google suggests that nobody else knows what it means either, but that it's entirely harmless. You should continue setting up your service.
– Michael Hampton♦
May 7 at 3:40
A quick trip through Google suggests that nobody else knows what it means either, but that it's entirely harmless. You should continue setting up your service.
– Michael Hampton♦
May 7 at 3:40
@MichaelHampton Ok, thakns. I will keep going with the tutorial and report any other issues, if that's ok.
– GiannisIordanou
May 7 at 3:56
@MichaelHampton Ok, thakns. I will keep going with the tutorial and report any other issues, if that's ok.
– GiannisIordanou
May 7 at 3:56
@MichaelHampton I have updated my question with the commands I run and the output I get.
– GiannisIordanou
May 7 at 20:42
@MichaelHampton I have updated my question with the commands I run and the output I get.
– GiannisIordanou
May 7 at 20:42
Going to xxx.xxx.xxx.xxx, the site is being served correctly, apart of the static files. I suppose there is an issue with the proper directories.
– GiannisIordanou
May 7 at 21:17
Going to xxx.xxx.xxx.xxx, the site is being served correctly, apart of the static files. I suppose there is an issue with the proper directories.
– GiannisIordanou
May 7 at 21:17
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "2"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f966107%2ferror-on-configuring-gunicorn%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Server Fault!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f966107%2ferror-on-configuring-gunicorn%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Hm, I think something went wrong with your paste, I could not see the error message the first time because of some strange characters. Probably your ssh connection is not using UTF-8 for some reason. I think it's fixed now, and I can see the error.
– Michael Hampton♦
May 7 at 3:30
A quick trip through Google suggests that nobody else knows what it means either, but that it's entirely harmless. You should continue setting up your service.
– Michael Hampton♦
May 7 at 3:40
@MichaelHampton Ok, thakns. I will keep going with the tutorial and report any other issues, if that's ok.
– GiannisIordanou
May 7 at 3:56
@MichaelHampton I have updated my question with the commands I run and the output I get.
– GiannisIordanou
May 7 at 20:42
Going to xxx.xxx.xxx.xxx, the site is being served correctly, apart of the static files. I suppose there is an issue with the proper directories.
– GiannisIordanou
May 7 at 21:17