Question

Just tell me if you ran the site and that was what you used

I just want to know, if in this community, there are some users who have been able to configure their site for django - gunicorn - nginx following the tutorial steps

Https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04

Or Https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04

Has managed to run its application and that is also visible in production by the number of ip and / or the domain name “www.xxxxxx.xx” and does not appear BAD 502. only that ??? If it works please report that you had success, to clear if there is something in my procedure or is some bug, suddenly if some I achieved using another system for example as dbain, please report please.

I have my doubts, since practically in all the forums my problem is in the air without RESOlVER.

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

Well every time I get more clear this matter, but I still can not run my application.

I commented that the application is at zero only has the minimum parameters in “settings.py” so that I launch “its work” from django.

I did everything carefully, according to the guide that you sent me and although it really helped me a lot I did not deploy the site, I only get the welcome to “nginx” and accessing the domain launches the welcome page of nginx, but accessing by ip Throw me bad 502.

Important thing I noticed, is that I do not see anywhere a “myproject.sock” file or I do not know where it is and checking the error log gives me the following.

Can you see that can be happening please ??

root@max:/home/max/myproject/myproject# sudo systemctl status gunicorn● gunicorn.service - gunicorn daemon Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Wed 2017-04-12 22:09:50 UTC; 12min ago Main PID: 24464 (code=exited, status=1/FAILURE)

Apr 12 22:09:45 max gunicorn[24464]: [2017-04-12 22:09:45 +0000] [24464] [INFO] Starting gunicor Apr 12 22:09:45 max gunicorn[24464]: [2017-04-12 22:09:45 +0000] [24464] [ERROR] Retrying in 1 s Apr 12 22:09:46 max gunicorn[24464]: [2017-04-12 22:09:46 +0000] [24464] [ERROR] Retrying in 1 s Apr 12 22:09:47 max gunicorn[24464]: [2017-04-12 22:09:47 +0000] [24464] [ERROR] Retrying in 1 s Apr 12 22:09:48 max gunicorn[24464]: [2017-04-12 22:09:48 +0000] [24464] [ERROR] Retrying in 1 s Apr 12 22:09:49 max gunicorn[24464]: [2017-04-12 22:09:49 +0000] [24464] [ERROR] Retrying in 1 s Apr 12 22:09:50 max gunicorn[24464]: [2017-04-12 22:09:50 +0000] [24464] [ERROR] Can’t connect t Apr 12 22:09:50 max systemd[1]: gunicorn.service: Main process exited, code=exited, status=1/FAI Apr 12 22:09:50 max systemd[1]: gunicorn.service: Unit entered failed state. Apr 12 22:09:50 max systemd[1]: gunicorn.service: Failed with result ‘exit-code’.

and log error:

2017/04/12 22:16:26 [crit] 24587#24587: *1 connect() to unix:/home/max/myproject/myproject.sock$ 2017/04/12 22:16:41 [crit] 24587#24587: *1 connect() to unix:/home/max/myproject/myproject.sock$ 2017/04/12 22:22:58 [crit] 24587#24587: *6 connect() to unix:/home/max/myproject/myproject.sock$ 2017/04/12 22:23:04 [crit] 24587#24587: *6 connect() to unix:/home/max/myproject/myproject.sock$ 2017/04/12 22:23:40 [crit] 24587#24587: *6 connect() to unix:/home/max/myproject/myproject.sock$ 2017/04/12 22:30:29 [crit] 24587#24587: *11 connect() to unix:/home/max/myproject/myproject.soc$ 2017/04/12 22:30:29 [crit] 24587#24587: *13 connect() to unix:/home/max/myproject/myproject.soc$

$t.sock failed (2: No such file or directory) while connecting to upstream, client: 181.163.181$ 2017/04/12 22:16:41 [crit] 24587#24587: *1 connect() to unix:/home/max/myproject/myproject.sock$ 2017/04/12 22:22:58 [crit] 24587#24587: *6 connect() to unix:/home/max/myproject/myproject.sock$ 2017/04/12 22:23:04 [crit] 24587#24587: *6 connect() to unix:/home/max/myproject/myproject.sock$ 2017/04/12 22:23:40 [crit] 24587#24587: *6 connect() to unix:/home/max/myproject/myproject.sock$ 2017/04/12 22:30:29 [crit] 24587#24587: *11 connect() to unix:/home/max/myproject/myproject.soc$ 2017/04/12 22:30:29 [crit] 24587#24587: *13 connect() to unix:/home/max/myproject/myproject.soc$

$63.181.193, server: 67.207.84.106, request: “GET / HTTP/1.1”, upstream: "http://unix:/home/max$ 2017/04/12 22:16:41 [crit] 24587#24587: *1 connect() to unix:/home/max/myproject/myproject.sock$ 2017/04/12 22:22:58 [crit] 24587#24587: *6 connect() to unix:/home/max/myproject/myproject.sock$ 2017/04/12 22:23:04 [crit] 24587#24587: *6 connect() to unix:/home/max/myproject/myproject.sock$ 2017/04/12 22:23:40 [crit] 24587#24587: *6 connect() to unix:/home/max/myproject/myproject.sock$ 2017/04/12 22:30:29 [crit] 24587#24587: *11 connect() to unix:/home/max/myproject/myproject.soc$ 2017/04/12 22:30:29 [crit] 24587#24587: *13 connect() to unix:/home/max/myproject/myproject.soc$

its so importan for me, that you givme a direction to do

@maxgonpe if you still have this issue it is because of the files stored in pycache folder. delete the ones you are replacing and restart gunicorn. They will be replaced with the new ones back into pycache folder.

@jtittle

Why the changes of my development server, are not reflected in the production server (views and urls)?

Hi, I am writing to see if you can help me with this: I happen is that I make changes in the development server and they work me well, but when I want to see them in production, I do not recognize them and I throw the error:

Page not found (404) Request Method: GET Request URL: http://www.maxsistemas.cl/casas/mipagina

I have tried all sorts of views, and called in urls, (all of them work in development, but nothing works for me in production) last clone a class definition that makes the same call and uses the same template but only change the name of the Definition to see if it works, and it happens to me the same everything works well in development, but when I want to see it in production, I throw the error mentioned at the beginning (404).

I have also tried, reloading nginx with several commands for me to take the changes, but the negative result even, these are the commands I tried:

Sudo systemctl daemon-reload Sudo systemctl start gunicorn Sudo systemctl restart nginx Sudo systemctl start nginx Sudo ufw allow ‘Nginx Full’

Thank you for the help, I do not know what else to try.

@jtittle

hellow again, send to you my regals:

I have no problem changing my database from sqlite3 to postgres. The problem is another, it is that when I generate the database in sqlite3 or postgres, the database is created by default with the ten tables of systems, but it does not take me into account, nor add the additional tables that are In the "models.py of my applications.

When I run “migrations” always tells me that there are no changes

When I run “migrate” list and our tables that are in my applications and are those that I am interested to include; However, he tells me not to migrate them and he does not explain why.

So I have tried to delete the files from the “migrations” folder and all the cache deleting the “.pyc” files, but I always get the basic table by default without the tables of my application, suddenly manipulating and manipulating in sqlite3 I have Achieved, but the one that interests me is postgres that is more robust for what I want.

That’s why I’m consulting you, if there is any way to reset the database and forget the whole history of migrations and can start from scratch ??? . I have also created new databases with another name, but the same is the basic database.

Well, I know it can be a problem of mine, rather than something I have forgotten in the design of my application, so I ask you to give me or guide me with some test or etc …

Thank you…

@jtittle

NOW ABOUT DATABASE POSTGRESS

Hello,

I tell you that I already take the trick to the issue of seeing the applications in production environment. And all thanks to you, since otherwise, would not have achieved.

Now I have a little problem, I want to share it if it has already happened to you. This is the postgres database, when I create the base and the user and I want to move from sqlite to postgres, I do not recognize the tables of the applications, there is no way that the “makemigrations” and “migrate” command add the tables Work, the only way to get it in pasandomen to sqlite. But I need a more robust database, since I do not trust much in sqilte. And if I want to pass me after updating the tables in sqlite for posgres I get the following error:

“CommandError:” migrate “is not a valid port number or address: port pair.”

I have already created two databases in postgres with new user and I have also tried to delete the “cache” of the migrations, but there is no way.

Do you have any idea of this topic ??

@jtittle

And solve by adding the ip in allow-host. And it was excellent.

Take care my friend, I say goodbye, here I am, it’s time to go to sleep.

Greetings bye

@jtittle

¡¡¡¡ ACCOMPLISHED!!!

Thanks, we did it (it was for your help that I could do it). Now I can see my site through the domain and that is what I wanted and needed. I ran two more commands according to the tutorial:

Sudo ufw delete allow 8000 Sudo ufw allow ‘Nginx Full’

The only thing I do not know if it is correct, is that now when I enter the number of ip, I get “welcome nginx” ??? , But I really do not care, since all this gave me a lot of war,

Thank you jtitle.

@maxgonpe

In your NGINX server block, i.e:

/etc/nginx/sites-available/myproject

You’ll need to change server_name to use your domain instead of an IP. So, this:

server_name 111.222.333.444;

Becomes:

server_name domain.com www.domain.com;

You would then point the A record for domain.com to the IPv4 IP of your Droplet. Once the changes have been made to your NGINX server block, you’d restart NGINX for the changes to take.

systemctl restart nginx

@jtittle

We almost did it,

I think this is the last one, after so much review and testing, including the permissions actions that you suggested to me. I managed to create the gunicorn.socket Among the actions I did was, to give permissions, to “max” the group “www-data” and to make a change in the /etc/systemd/system/gunicorn.service

In the directory WorkingDirectory = / home / max / myproject

by: WorkingDirectory = / my home / max / myproject / myproject

now : i can see my page “working it” from django when i used de ip but when use the domain , only “nginx working”

but must importan that i have a “myproject.sock” create.

some things else ? for win

@jtittle

I know you did everything you could to help me, so on that side you have an “A” jee jee. But I will also see the issue of permissions in files and directories. Before closing the thread in this thread. I would like to know what you ask about:


I’m curious, suppose you are not working with a virtual environment, but directly everything as it is and has the server for all software, configurations and users? Then how could be the correct way to address the same of this instruction, but without virtual environment:

ExecStart=/home/sammy/myproject/myprojectenv/bin/gunicorn --workers 3 -u sammy -g www-data --bind unix:/home/sammy/myproject/myproject.sock myproject.wsgi:application

exits for no virtual enviroment? How would the syntax be?

Come to this situation testing possibilities for it to work, and thinking that maybe it is the virtual environment that complicates something this.

It will be possible??


After you answer this, I do not bother you anymore and I close the thread.

And thank you, very grateful for all your help.

@jtittle

I followed step by step very carefully all the tutorial and check up to the smallest detail, everything works well, as I go through the configuration, but in the end, only shows me the welcome to Nginx. what will happen? Can you tell me that I use to run the ubuntu xx.xx configuration ??

In case something indicates this information, what are you going to see?

root@max:/home/max/myproject/myproject# sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful root@max:/home/max/myproject/myproject# sudo systemctl restart nginx root@max:/home/max/myproject/myproject# sudo systemctl status nginx ● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2017-04-13 19:58:07 UTC; 5min ago Process: 7519 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/ng Process: 7534 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status= Process: 7524 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited Main PID: 7541 (nginx) Tasks: 2 (limit: 4915) Memory: 2.5M CPU: 29ms CGroup: /system.slice/nginx.service ├─7541 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; └─7544 nginx: worker process

Apr 13 19:58:07 max systemd[1]: Starting A high performance web server and a reverse proxy serve Apr 13 19:58:07 max systemd[1]: nginx.service: Failed to read PID from file /run/nginx.pid: Inva Apr 13 19:58:07 max systemd[1]: Started A high performance web server and a reverse proxy server ESCOC

and error.log

2017/04/13 19:58:33 [error] 7544#7544: *1 connect() to unix:/home/max/myproject/myproject.sock failed (111: Connection refused) while connecting to upstream, client: 181.163.145.226, server: 67.207.84.106, request: “GET / HTTP/1.1”, upstream: “http://unix:/home/max/myproject/myproject.sock:/”, host: “67.207.84.106”