I have gunicorn successfully installed
Every time I run this command:
$ gunicorn hello.wsgi:application --bind example.com:8001
I get this error:
[INFO] Starting gunicorn 18.0
[ERROR] Invalid address: ('example.com', 8001)
I am following this tutorial:
http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/
example.com is just an example domain. Use 0.0.0.0:8001 as bind address instead.
gunicorn hello.wsgi:application --bind 0.0.0.0:8001
I had the same problem.
Let's look:
First we have the 'public_html' folder for the web sites, then we have the virtualenv folder apps 'mysite'
Then, in 'mysite' you have 'myapp' Django, inside that there are another 'myapp' folder with the wsgy.py file.
So inside your django app first folder you run:
gunicorn myapp.wsgi:application --bind site.com:8001
Related
I am trying to deploy python app in my centos7 using flask and gunicorn.
but i found that the app is not able to retrive variables from .env file.
It is working on my local vm.
I am using gunicorn --bind 0.0.0.0:5000 app:app
pls help.
So, just configure a service file app.service in /etc/systemd/system and add EnvironmentFile=/path_to_env_file under [service] and start the service.
For more info on configuring the env file in gunicorn service, you can see
here.
I've followed this guide (https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04), but I'm presently seeing the following when trying to run gunicorn via the gunicorn service file (/etc/systemd/system/gunicorn.service):
Oct 04 11:30:22 ukgcdeploy01 gunicorn[8095]: File "/opt/envs/automation-console-env/bin/gunicorn", line 5, in <module>
Oct 04 11:30:22 ukgcdeploy01 gunicorn[8095]: from gunicorn.app.wsgiapp import run
Oct 04 11:30:22 ukgcdeploy01 gunicorn[8095]: ModuleNotFoundError: No module named 'gunicorn'
The gunicorn.service file contains the following:
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/opt/envs/automation-console-env
ExecStart=/opt/envs/automation-console-env/bin/gunicorn --timeout 600 --log-level debug --error-log /var/log/automation-console-env_error.log --access-logfile /var/log/automation-console-env_access.log --workers 3 --bind unix:/opt/envs/automation-console-env/automation-console-env.sock django_forms.wsgi:application
[Install]
WantedBy=multi-user.target
Running gunicorn manually works fine:
gunicorn --bind 0.0.0.0:8000 myproject.wsgi
This was previously working before I had to upgrade my Python version from 3.5.2 to 3.9, and due to some issues I ended up having to recreate the virtual environment, so I don't think it's necessarily an issue with the service file, but rather my Python/Gunicorn installation.
If anyone could offer some advice, it would be greatly appreciated :)
Does the automation-console-env environment exist? If so, is gunicorn installed there? In either case, since it is working as gunicorn ... on the command line, you should be able to use this installation.
which gunicorn
Then change your systemd unit file to point to this executable.
It seems that you either are defining the wrong path or you might be facing a permission issue in gunicorn.service.
First try to enable the service by using systemctl enable gunicorn.service. If it didn't work, then try the following:
Edit gunicorn.service as follows:
from: --bind unix:/opt/envs/automation-console-env/automation-console-env.sock django_forms.wsgi:application
to: --bind unix:/opt/envs/automation-console-env/automation-console-env.sock django_forms.wsgi
So I am a beginner in docker and Django. What I have here is a django app which I am trying to dockerize and run. My requirements.txt has only django and gunicorn as the packages.
I am getting the below in terminal after building and running the docker image:
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
August 26, 2021 - 06:57:22
Django version 3.2.6, using settings 'myproject.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
Below is my Dockerfile:
FROM python:3.6-slim
ENV PYTHONUNBUFFERED=1
RUN mkdir /Django
WORKDIR /Django
ADD . /Django
RUN pip install -r requirements.txt
EXPOSE 8000
CMD python manage.py runserver 0.0.0.0:8000
The commands I am using are:
docker build . -t myproj
docker run -p 8000:8000 myproj
I have tried adding allowedhosts = ['127.0.0.1'] in settings.py but still I am getting "The site can't be reached. 127.0.0.1 refused to connect.
Not able to see the "Congratulations" screen.
Please help me out with this.
P.s: I am using windows machine
Updates
I tried running the below line and got the following output:
docker exec 8e6c4e4a58db curl 127.0.0.1:8000
OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: \"curl\": executable file not found in $PATH": unknown
Without your settings.py, this can be hard to figure out. You say you have allowedhosts = ['127.0.0.1'] in there and that should definitely not be necessary. It might actually be what's blocking your host, since requests from your host come from a different IP address.
I've made the following Dockerfile that creates a starter project and runs it
FROM python:latest
RUN python -m pip install Django
RUN django-admin startproject mysite
WORKDIR /mysite
EXPOSE 8000
CMD python manage.py runserver 0.0.0.0:8000
If I build it and run it with
docker build -t mysite .
docker run -d -p 8000:8000 mysite
I can connect to http://localhost:8000/ on my machine and get the default page (I'm on Windows too).
I hope that helps you to locate your issue.
PS: Your curl command fails because curl isn't installed in your image, so it failing has nothing to do with your issue.
I have this ProcFile file following this guidelines for django app deployment on section Build your app and run it locally in order to test it locally you have to run this command.
web: python manage.py runserver 0.0.0.0:$PORT
Then running heroku local or heroku local web got me into this error:
CommandError: "0.0.0.0:$PORT" is not a valid port number or address:port pair.
You must not use runserver in production. Use gunicorn as the docs and comments suggest.
For local:
If you follow this official heroku tutorial and you are running it on Window platform locally, instead of $PORT, you have to use %PORT% at your Procfile.windows:
web: python manage.py runserver 0.0.0.0:%PORT%
since window does not interpret $PORT expression which only applicable in Unix shells.
If one using waitress as WSGI and wanna run it locally on Window platform, your Procfile should looks like this:
web: waitress-serve --port=%PORT% wsgi:your_app
For real online deployment:
simply include gunicorn package in requirementx.txt and your Procfile should be in this way:
web: gunicorn wsgi:your_app
If you are using waitress, you need to change back to $PORT, and set it in this way instead of fixed port number since Heroku assigns port to your app dynamically. Also, do make sure the host is set to 0.0.0.0 so your app is available externally.
For a django project in heroku you must have a Procfile like this:
web: gunicorn yourapp.wsgi
The filename must be Procfile, and not ProcFile
If you want to run into development you can either $ python manage.py runserver in your shell (heroku independent) or run $ heroku local with a valid production Procfile
I cannot seem to find a solid answer to this after scouring the web for answers. Currently, I have my directory set up this way:
flaskapp
-app
-intro_to_flask
+__init__.py
+config.py
+routes.py
+forms.py
-runserver.py
-Readme.md
-bin
-include
-lib
-view
Procfile
requirements.txt
So I not sure whether the Procfile is set up correctly...I have it set up this way:
web: gunicorn --pythonpath app runserver
However, when I run foreman start...heroku goes into a loop that keeps restarting the connection, I tried manually setting the port in the virtual environment export PORT=5001, but I am still getting the same error:
Running on http://127.0.0.1:5000/
12:21:20 web.1 | * Restarting with reloader
12:21:20 web.1 | 2014-02-22 12:21:20 [34532] [INFO] Starting gunicorn 18.0
12:21:20 web.1 | 2014-02-22 12:21:20 [34532] [ERROR] Connection in use: ('0.0.0.0', 5001)
Also, I have killed all gunicorn processes that are in used and tried running foreman start again...any ideas what could be going on?
Here is my runserver.py
from intro_to_flask import app
app.run(debug=True)
When you run your app on gunicorn you do not use the same starter script that starts the development server. All gunicorn needs to know is from where to import the application. In your case I think what you want in your Procfile is something like this:
web: gunicorn --pythonpath app intro_to_flask:app
Not sure if this will work as is or if you will need to make minor tweaks. The idea is that you need to give gunicorn the package or module that defines the application, then a colon, and then the application instance symbol.
I hope this helps.