nginx + uwsgi + debian deploy django

There are many similar articles on the Internet. This article briefly describes my deployment process.

Environment description: debian, python3.6, Django1.11 

1. Running the django project will not go into details on startup: python3 manage.py runserver 0:8899

2. Use uwsgi to provide services

    1. Install uwsgi: pip3 install uwsgi

    2、启动uwsgi :  uwsgi --http 127.0.0.1:8899 --module project_name.wsgi

    You can run your web project. Enter 127.0.0.1:8899 in the browser to access the project. If you can access it successfully, it means that this step is successfully deployed.

3. Deploy to nginx

    1、安装nginx : apt-get install nginx 

    2. Set up the nginx configuration file

        Because there are default configurations in the /etc/nginx/nginx.conf configuration file, include all .conf configuration files in the /etc/nginx/conf.d/ directory. For the convenience of management, create them under the /etc/nginx/conf.d/ directory. Your own web project configuration file, such as creating a new my_site.conf file, the specific configuration information is as follows:

    server {

    listen 80; #The port on which the started nginx process listens for requests

    server_name localhost; #domain name

    error_log /var/log/nginx/project_name/error.log; #nginx error log, you can set it yourself, but you must ensure that the directory and file are established in advance

    location / {

        include /etc/nginx/uwsgi_params;

        uwsgi_pass 127.0.0.1:8899; #For dynamic requests, forward to port 9090 of this machine, which is the port that uwsgi listens to

    }

    #error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;

     location = /50x.html {

        root /usr/share/nginx/html;

   }

    location /static/ {

        alias /var/www/nginx/manage/static/; #Set the directory where the static files are located

    }

    location /media/ {

        alias /var/www/nginx/manage/media/; #Also set by yourself, make sure the directory has been built

    }

}

After the configuration file is written, we need to check the correctness of the configuration file:

nginx -t -c /etc/nginx/nginx.conf

  3. Synchronize static files to the directory set by nginx

    First add STATIC_ROOT='/var/www/manage/static/ to the Django project setting.py

    Execute sync python manage.py collectstatic on command line to automatically copy all static files to nginx index directory

   4. Start uwsgi

    In the django project directory uwsgi --socket 127.0.0.1:8899 --module project_app.wsgi

    5. Start nginx

    Start command: service nginx start The page can be accessed after normal startup

Fourth, the problems encountered

    1、问题:nginx connect() failed (111: Connection refused) while connecting to upstream

    Reason: php-fpm is not installed or not started properly

    View PHP process status service php5-fpm status

    Not working properly, modify listen = 127.0.0.1:9000; 9000 in /etc/php5/fpm/pool.d/www.conf

 

 

   

 

 

 

 


 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324992052&siteId=291194637