Gunicorn sever can not start in Ubuntu
Gunicorn sever can not start in Ubuntu
I am deploying a flask project with Nginx, Gunicorn and Ubuntu Linux server. Currently, I have already done something and the server can be started manually with the command
gunicorn -w 4 -b 127.0.0.1:5000 run:app
Followings is the content of nginx.conf
user www www;
worker_processes 2;
error_log /usr/local/webserver/nginx/logs/nginx_error.log crit;
pid /usr/local/webserver/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
use epoll;
worker_connections 65535;
}
http
{
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
#charset gb2312;
# server_names_hash_bucket_size 128;
# client_header_buffer_size 32k;
# large_client_header_buffers 4 32k;
# client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 60 ;
fastcgi_send_timeout 60;
fastcgi_read_timeout 60;
fastcgi_buffer_size 128k;
fastcgi_buffers 8 128k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
limit_zone crawler $binary_remote_addr 10m;
server {
listen 80;
server_name schoolping.westeurope.cloudapp.azure.com;
index index.html index.htm index.php;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
If I just start with gunicorn -w 4 -b 127.0.0.1:5000 run:app, the website can only be available for a while, and then if I try to access to the website with DNS, it showed to me 504 Error.
To fix the issue, I am trying to make the Gunicorn start automatic. So I created a file named School.service
in /etc/systemd/system/
Contents of the file is shown as followings:
School.service
/etc/systemd/system/
[Unit]
Description=Gunicorn instance to serve Flasky
After=network.target syslog.target
[Service]
User=www
Group=www
WorkingDirectory=/home/schoolproject/www/nginx-1.6.3/venv/bin/School
#Environment="path=/home/schoolproject/www/nginx-1.6.3/venv/bin"
ExecStart=/home/schoolproject/www/nginx-1.6.3/venv/bin/School/Code gunicorn -w 4 -b 127.0.0.1:5000 run:app
[Install]
WantedBy=multi-user.target
School is the fold of the project, and run.py is the execution file, argus is "app". After I start the service by
systemctl daemon-reload School
systemctl start School
Then I checked the status of the service by
systemctl status School
It shows me that:
> School.service - Gunicorn instance to serve Flasky Loaded: loaded
> (/etc/systemd/system/School.service; enabled; vendor preset: enabled)
> Active: failed (Result: exit-code) since Wed 2018-07-25 19:06:48 UTC;
> 23s ago Process: 34291
> ExecStart=/home/schoolproject/www/nginx-1.6.3/venv/bin/School/Code
> gunicorn -w 4 -b 127.0.0.1:5000 run:app (code=exited, status=203/EXEC)
> Main PID: 34291 (code=exited, status=203/EXEC)
> CPU: 740us
>
> Jul 25 19:06:48 School systemd[1]: Started Gunicorn instance to serve
> Flasky. Jul 25 19:06:48 School systemd[34291]: School.service: Failed
> at step EXEC spawning
> /home/schoolproject/www/nginx-1.6.3/venv/bin/School/Code: Permission
> denied Jul 25 19:06:48 School systemd[1]: School.service: Main process
> exited, code=exited, status=203/EXEC Jul 25 19:06:48 School
> systemd[1]: School.service: Unit entered failed state. Jul 25 19:06:48
> School systemd[1]: School.service: Failed with result 'exit-code'.
The error is permission denied, but I have already make the user "www" as the owner of the folder /home/schoolproject/
.
I do not know how to do next to fix the issue.
Anyone are give me a hand?
/home/schoolproject/
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.