I do according to the documentation . Install uwsgi and nginx turned out. I downloaded the file uwsgi_params , created the file mysite_nginx.conf

 # mysite_nginx.conf # the upstream component nginx needs to connect to upstream django { # server unix:///path/to/your/mysite/mysite.sock; # for a file socket server 127.0.0.1:8001; # for a web port socket (we'll use this first) } # configuration of the server server { # the port your site will be served on listen 8000; # the domain name it will serve for server_name localhost; # substitute your machine's IP address or FQDN charset utf-8; # max upload size client_max_body_size 75M; # adjust to taste # Django media location /media { alias /home/ubuntu/myproject/mysite/friends_plans/media; # your Django project's media files - amend as required } location /static { alias /home/ubuntu/myproject/mysite/friends_plans/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 /home/ubuntu/myproject/mysite/uwsgi_params; # the uwsgi_params file you installed } } 

Completed commands

 $ sudo ln -s ~/path/to/your/mysite/mysite_nginx.conf /etc/nginx/sites-enabled/ $ python manage.py collectstatic $ sudo /etc/init.d/nginx restart 

I try to enter the browser localhost:8000 , the inscription "Unable to connect. Firefox can't create a connection to the server at localhost: 8000 ..." appears.

Using port 80, a nginx greeting appears. View the file with logs does not work. I executed the command /var/log/nginx/error.log , at first the answer was "permission denied", I tried a lot of things, now I ended up with "file busy". Tell me, please, what could be wrong and what should be done to start the server? Thanks a lot in advance!

 (myvenv) ubuntu@ubuntu-VirtualBox:~/myproject/mysite$ sudo lsof -Pn -iTCP - sTCP:LISTEN [sudo] password for ubuntu: COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME dnsmasq 1039 nobody 5u IPv4 15044 0t0 TCP 127.0.1.1:53 (LISTEN) mysqld 1068 mysql 21u IPv4 16409 0t0 TCP 127.0.0.1:3306 (LISTEN) java 2285 ubuntu 142u IPv4 21541 0t0 TCP 127.0.0.1:6942 (LISTEN) java 2285 ubuntu 203u IPv4 22124 0t0 TCP 127.0.0.1:63342 (LISTEN) cupsd 2627 root 10u IPv6 24962 0t0 TCP [::1]:631 (LISTEN) cupsd 2627 root 11u IPv4 24963 0t0 TCP 127.0.0.1:631 (LISTEN) nginx 4230 root 6u IPv4 53589 0t0 TCP *:80 (LISTEN) nginx 4230 root 7u IPv6 53590 0t0 TCP *:80 (LISTEN) nginx 4231 www-data 6u IPv4 53589 0t0 TCP *:80 (LISTEN) nginx 4231 www-data 7u IPv6 53590 0t0 TCP *:80 (LISTEN) nginx 4232 www-data 6u IPv4 53589 0t0 TCP *:80 (LISTEN) nginx 4232 www-data 7u IPv6 53590 0t0 TCP *:80 (LISTEN) nginx 4233 www-data 6u IPv4 53589 0t0 TCP *:80 (LISTEN) nginx 4233 www-data 7u IPv6 53590 0t0 TCP *:80 (LISTEN) nginx 4234 www-data 6u IPv4 53589 0t0 TCP *:80 (LISTEN) nginx 4234 www-data 7u IPv6 53590 0t0 TCP *:80 (LISTEN) (myvenv) ubuntu@ubuntu-VirtualBox:~/myproject/mysite$ (myvenv) ubuntu@ubuntu-VirtualBox:~/myproject/mysite$ service uwsgi status ● uwsgi.service - LSB: Start/stop uWSGI server instance(s) Loaded: loaded (/etc/init.d/uwsgi) Active: failed (Result: exit-code) since Fri 2016-06-03 03:26:09 EDT; 1 day 3h ago Docs: man:systemd-sysv-generator(8) Process: 1313 ExecStart=/etc/init.d/uwsgi start (code=exited, status=127) Jun 03 03:26:09 ubuntu-VirtualBox systemd[1]: Starting LSB: Start/stop uWSGI.... Jun 03 03:26:09 ubuntu-VirtualBox uwsgi[1313]: /etc/init.d/uwsgi: line 72: /...y Jun 03 03:26:09 ubuntu-VirtualBox uwsgi[1313]: /etc/init.d/uwsgi: line 73: /...y Jun 03 03:26:09 ubuntu-VirtualBox uwsgi[1313]: * Starting app server(s) uwsgi Jun 03 03:26:09 ubuntu-VirtualBox uwsgi[1313]: /etc/init.d/uwsgi: line 80: d...d Jun 03 03:26:09 ubuntu-VirtualBox uwsgi[1313]: ...fail! Jun 03 03:26:09 ubuntu-VirtualBox systemd[1]: uwsgi.service: control process...7 Jun 03 03:26:09 ubuntu-VirtualBox systemd[1]: Failed to start LSB: Start/sto.... Jun 03 03:26:09 ubuntu-VirtualBox systemd[1]: Unit uwsgi.service entered fai.... Jun 03 03:26:09 ubuntu-VirtualBox systemd[1]: uwsgi.service failed. Hint: Some lines were ellipsized, use -l to show in full. 
  • sudo nginx -t what gives? To read logs use sudo less /var/log/nginx/error.log (exit with the q button) - andreymal
  • Andrew, sudo nginx -t gives nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is sucsessful - Anastasia Novikova
  • Strange, and sudo ls /etc/nginx/sites-enabled/ ? There must be mysite_nginx.conf , and if it doesn’t, it means ln -s didn’t run - andreymal
  • When you run the sudo less /var/log/nginx/error.log command for the first time, there were many lines with only the ~ character (but this is probably because I had not tried to go to localhost: 8000 in the browser), now every time starts sudo less /var/log/nginx/error.log (END) - Anastasia Novikova
  • By the command sudo ls /etc/nginx/sites-enabled/ issued default mysite_nginx.conf - Anastasia Novikova

1 answer 1

  1. The configuration files should not be in your home directory, but in the /etc/nginx directory and / or its subdirectories. so:

    1. Copy your "sites" file to its proper place:

       $ sudo cp ~/path/to/your/mysite/mysite_nginx.conf /etc/nginx/sites-available/ 
    2. create a symbolic link ( symlink ) to this file in the “included” sites directory:

       $ sudo ln -sf ../sites-available/mysite_nginx.conf /etc/nginx/sites-enabled/ 
  2. The nginx-common package , of course, includes the normal uwsgi_params distribution file. use some kind of "left", and even the devil knows where it is located - does not make sense. therefore, I recommend replacing the line:

     include /home/ubuntu/myproject/mysite/uwsgi_params; 

    on:

     include uwsgi_params; 
  3. as usual after making changes to the configuration, it makes sense to check it (by means of the nginx program itself):

     $ sudo service nginx configtest 

    if the team returns something like:

     [ ok ] Testing nginx configuration:. 

    then the configuration is fine. if you get something else, attach it to the question - we will help you to understand and eliminate errors.

  4. If the configuration check was successful, restart the nginx program:

     $ sudo service nginx restart 
  5. after that in the output of the command I proposed:

     $ sudo lsof -Pn -iTCP -sTCP:LISTEN 

    You should see the nginx processes that are listening not only on port 80 ( TCP *:80 (LISTEN) ), but on the 8000th port you specified ( TCP *:8000 (LISTEN) ).

    if you do not see, attach the command output to the question:

     $ sudo service nginx status 
  6. in the nginx configuration, you have indicated to redirect calls to the address 127.0.0.1 , port 8001 . but in the output of the lsof program you enclosed, I do not observe any processes listening to this port. as far as I understand, in the manual, the link to which you gave, this should be handled by a certain manage.py script, which is either run like this:

     $ python manage.py runserver 0.0.0.0:8001 

    either in this way:

     $ uwsgi --http :8001 --module mysite.wsgi 
  7. Run command /var/log/nginx/error.log

    this is not a team. This is a text file that can be viewed using, for example, the less program:

     $ less /var/log/nginx/error.log 
  • Everything written is meaningless if nginx stupidly does not want to listen to port 8000 - andreymal
  • @andreymal, maybe. Problem localization plan: 1. content analysis /etc/nginx/nginx.conf . 2. finding out what the program under the name nginx works on the system: perhaps this is not at all the program that was installed as part of the nginx package .... // these will be the following questions. - aleksandr barakin pm
  • Thanks a lot for your help! After the operations, the server now listens to port 8000. But when I try to enter the localhost: 8000 page in the browser, I get an error 502 Bad Gateway. With her, too, can not figure out. But, if I understood correctly, it’s not connected with nginx, but rather with uwsgi. - Anastasia Novikova
  • In general, I have a project called python manage.py runserver at 127.0.0.1:8000/application_name/... Probably 8001 for uwsgi. - Anastasia Novikova
  • In the file with logs [error] 4624#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "uwsgi://127.0.0.1", host: "localhost:8000" . If you entered some address of the page of your project the same error, but only in the file with the GET logs the corresponding request. - Anastasia Novikova