I am trying to implement nginx + django + gunicorn for my project deployment. I am taking the help of following article:
http://tutos.readthedocs.io/en/latest/source/ndg.html . I followed the steps as described. Now, I am trying to start gunicorn. What am I getting at the screen is:
$ gunicorn ourcase.wsgi:application
[2016-05-19 19:24:25 +0000] [9290] [INFO] Starting gunicorn 19.5.0
[2016-05-19 19:24:25 +0000] [9290] [INFO] Listening at: http://127.0.0.1:8000 (9290)
[2016-05-19 19:24:25 +0000] [9290] [INFO] Using worker: sync
[2016-05-19 19:24:25 +0000] [9293] [INFO] Booting worker with pid: 9293
Since, I am new to nginx & gunicorn, I am not sure whether the above is an error or not. I am getting nothing in error log
cat /var/log/nginx/error.log
It prints nothing on the screen. Please help me to solve this.
That output means that the process is running. Which is what you want. You should try accessing the URL from the browser directly after running the command without pressing ctrl+c.
As a side note you can write a bash script to do this which will make it easier to add arguments to the gunicorn commands.
I have a gist that does just that. https://gist.github.com/marcusshepp/129c822e2065e20122d8
Let me know what other questions you might have and I'll add a comment.
Related
I am working on a Windows 10 machine using Ubuntu inside WSL. I did this because I cannot get gunicorn to work as I've researched it is not available in Windows. I can successfully run my app using my docker-compose file within my WSL Ubuntu perfectly fine. I then run the gunicorn myapp.wsgi command and the server spins up with the terminal giving me the following output:
[2021-09-16 19:11:53 +0000] [25] [INFO] Starting gunicorn 20.1.0
[2021-09-16 19:11:53 +0000] [25] [INFO] Listening at: http://127.0.0.1:8000 (25)
[2021-09-16 19:11:53 +0000] [25] [INFO] Using worker: sync
[2021-09-16 19:11:53 +0000] [26] [INFO] Booting worker with pid: 26
However, I cannot connect to my site at localhost:8000. I also did a curl request against the localhost:8000 from inside my docker container and got a 302 error.
I've researched using gunicorn, mod_wsgi and uwsgi, all given as options in the Django documentation. However, I want to use gunicorn or uwsgi to have access to either nginx or Apache (plus the documentation on mod_wsgi has a dead link for the windows install file). Does anyone have suggestions on how I can get this to work?
I am new to server and apps.
Currently, I have created an app on my aws instance.
gunicorn --threads 4 -b 0.0.0.0:5000 --access-logfile server.log --timeout 60 server:app
But I want to keep it running after I ssh the instance, how could I achieve this?
[2018-09-24 17:45:28 +0000] [8318] [INFO] Starting gunicorn 19.9.0
[2018-09-24 17:45:28 +0000] [8318] [INFO] Listening at:
http://0.0.0.0:5000 (8318)
[2018-09-24 17:45:28 +0000] [8318] [INFO] Using worker: threads
[2018-09-24 17:45:28 +0000] [8321] [INFO] Booting worker with pid: 8321
I have to use control+c to exit too at the moment.
add --daemon to your command line or use screen (https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-14-04)
I have a script that hits a simple API on all my servers every hour to ensure they are functioning properly. My newest server isn't using my normal stack, so I suspect I've configured it improperly. It is currently returning occasional 404 errors to the logging script.
Server Config
Ubuntu, Nginx, PostgreSQL, Supervisor;
Running a Docker container with Django/Wagtail and Gunicorn.
Looks fine when I visit in webbrowser, but my script logged four 404s in the last 12 hours.
My supervisor log shows the 404s but doesn't provide any additional useful information:
[2018-07-16 20:22:35 +0000] [9] [INFO] Booting worker with pid: 9
[2018-07-16 20:22:35 +0000] [10] [INFO] Booting worker with pid: 10
[2018-07-16 20:22:35 +0000] [11] [INFO] Booting worker with pid: 11
Not Found: /_server_health/
Not Found: /_server_health/
Not Found: /_server_health/
There is no relevant information captured in the Nginx log.
Can anyone recommend any steps I can take to gather further information? Or does this fit the pattern of any known problematic server configs?
Edit: It looks like Wagtail is sometimes causing the 404: "Raised by: wagtail.core.views.serve"
Maybe a problem in my urls.py? Should this be configured differently for Wagtail?
url(r'^_server_health$', status_api),
In my Django settings and on my machine I have utc+3 configured time so the expectations were to get all logs in utc+3, but turned out, that actually they are pretty messy:
[2017-08-08 10:29:22 +0000] [1] [INFO] Starting gunicorn 19.7.1
[2017-08-08 10:29:22 +0000] [1] [DEBUG] Arbiter booted
[2017-08-08 10:29:22 +0000] [1] [INFO] Listening at: http://0.0.0.0:8000
[2017-08-08 10:29:22 +0000] [1] [INFO] Using worker: sync
[2017-08-08 10:29:22 +0000] [7] [INFO] Booting worker with pid: 7
[2017-08-08 10:29:23 +0000] [1] [DEBUG] 1 worker
[2017-08-08 13:29:26 +0300] [7] [INFO] [dashboard.views:9] Displaying menu
Settings:
TIME_ZONE = 'Europe/Moscow'
USE_TZ = True
Maybe you can provide some hints/information how to configure or debug it?
For a moment I thought that this is a gunicorn's problem, but it uses Django settings soo I have no idea what's wrong :/
Gunicorn logging time do not relay on Django timezone, but in the local machine one, so to get the right timezone you should configure your local machine and how to do it depends in what OS is running on it.
For Debian/Ubuntu:
sudo dpkg-reconfigure tzdata
Follow the directions in the terminal.
The timezone info is saved in /etc/timezone - which can be edited or used below
If you are using CentOS you can check it in this article.
For other options, check it in Google.
Hope that it helps.
So, the timestamps were correct, but different because of my company proxy settings. Also it turned out that is best way to handle different time zones is just use utc everywhere except presentation to user.
I am trying to host a Django Node app on heroku. And my procfile looks like this
web: gunicorn backend courier.wsgi:application --bind 0.0.0.0:$PORT & node frontend/server.js
My server.js runs the index.html. And my is showing the index.html page. But the Django urls do not work.
And my heroku logs show this.
2016-02-28T17:25:40.032724+00:00 app[web.1]: [2016-02-28 17:25:40 +0000] [7] [INFO] Starting gunicorn 19.3.0
2016-02-28T17:25:40.258117+00:00 heroku[web.1]: State changed from starting to up
2016-02-28T17:25:41.042335+00:00 app[web.1]: [2016-02-28 17:25:41 +0000] [7] [ERROR] Connection in use: ('0.0.0.0', 46831)
2016-02-28T17:25:41.042419+00:00 app[web.1]: [2016-02-28 17:25:41 +0000] [7] [ERROR] Retrying in 1 second.
And my gunicorni doesn't start.
However, when i remove & node frontend/server.js from my procfile it runs the django app normally and all my Django URLs work.
Would be great if somebody could tell me what is wrong here. Thanks in advance.
I dont think you can have two ports for two different processes on a single heroku dyno.
You might have to use another dyno to run the other.
Also I suggest putting the frontend pages as static files and serving them through Django.