Gunicorn服务器无法在Ubuntu中启动

时间:2018-07-25 19:23:30

标签: ubuntu nginx flask gunicorn

我正在与Nginx,Gunicorn和Ubuntu Linux服务器一起部署Flask项目。目前,我已经完成了一些操作,可以使用命令

手动启动服务器
gunicorn -w 4 -b 127.0.0.1:5000 run:app 

以下是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;
        }

}
}

如果我只是从gunicorn -w 4 -b 127.0.0.1:5000 run:app开始,则该网站只能使用一段时间,然后,如果我尝试使用DNS访问该网站,则会显示给我504错误。

为解决此问题,我正在尝试使Gunicorn自动启动。因此,我在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

学校是项目的主要部分,run.py是执行文件,argus是“ app”。在我启动服务后

systemctl daemon-reload School
systemctl start School

然后我通过

检查了服务的状态
systemctl status School 

它告诉我:

>  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'.

错误是权限被拒绝,但是我已经使用户“ www”成为文件夹/home/schoolproject/的所有者。 enter image description here 我不知道下一步该怎么解决。 有人帮我吗?

0 个答案:

没有答案