How do I deploy a Flask application in IIS 8 (Windows Server 2012)? There are many partial explanations around, but nothing seems to work.
Just in case. I wouldn't do anything of this in production for complex and important app.
I'd go for reverse proxy + gunicorn. That's what I do most of the times nowadays but with nginx and on linux machines. The problem here is that gunicorn doesn't support windows for now (but support is planned). Now you have an option to run your Flask app with gunicorn in Cygwin.
The other way around would be to try this https://serverfault.com/questions/366348/how-to-set-up-django-with-iis-8 but instead of Django related stuff and especialy
from django.core.handlers.wsgi import WSGIHandler as DjangoHandler
you need your Flask paths and env variables and
from yourapplication import app as FlaskHandler
NB: instead of gunicorn you can try other launchers listed here. May be there's more luck with Twisted or Tornado on Windows
Update: Gunicorn in Cygwin
I'm on Window 7 64bit with Cygwin 1.7.5 32bit. Python version 2.6.8.
I had some issues running Flask with Cygwin 64bit and Python 2.7 although gunicorn seemed to work ok.
You can get Cygwin here.
Packages I've installed:
nano
python 2.6.8
curl
Then I installed pip with:
$ curl https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py | python
$ easy_install pip
And then flask and gunicorn:
$ pip install flask gunicorn
I've made simple app.py:
from flask import Flask
app = Flask(__name__)
#app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
And run it with gunicorn:
$ gunicorn app:app
2013-11-27 16:21:53 [8836] [INFO] Starting gunicorn 18.0
2013-11-27 16:21:53 [8836] [INFO] Listening at: http://127.0.0.1:8000 (8836)
2013-11-27 16:21:53 [8836] [INFO] Using worker: sync
2013-11-27 16:21:53 [6140] [INFO] Booting worker with pid: 6140
After that you'll need to make your gunicorn app to run like windows service. But that part I haven't done for a long time so memories are shaded:)
NB: I've found another option https://code.google.com/p/modwsgi/wiki/InstallationOnWindows if you are ready to try
I had more success with this method using FastCGI: http://codesmartinc.com/2013/04/12/running-django-in-iis7iis8/
Just use (yourModule).app instead of django.core.handlers.wsgi.WSGIHandler() for the WSGI_Handler variable.
Related
I'm running Django web app on a docker container where I use Nginx with uwsgi.
Overall the web works just fine it fails only on specific callback endpoints during the social app (Google, Facebook) registration.
Below is the command I use to run the uswgi
uwsgi --socket :8080 --master --strict --enable-threads --vacuum --single-interpreter --need-app --die-on-term --module config.wsgi
Below is the endpoint where it fails (Django allauth lib)
accounts/google/login/callback/?state=..........
Below is the error message:
!! uWSGI process 27 got Segmentation Fault !!!
...
upstream prematurely closed connection while reading response header from upstream, client: ...
...
DAMN ! worker 1 (pid: 27) died :( trying respawn ...
Respawned uWSGI worker 1 (new pid: 28)
Just FYI.. this works without any issues in the local docker container but it fails when I use the GCP container. Also, this used to work fine on GCP as well so probably something happened after recent dependency updates.
Environment:
Python: 3.9.16
Django: 3.2.3
allauth: 0.44.0 (Django authentication library)
Nginx: nginx/1.23.3
uWSGI: 2.0.20
I try to deploy my django project on heroku, and follow commands below
heroku login
git init
git add .
git commit -m "first commit"
heroku create
heroku git:remote -a name
pip install gunicorn
gunicorn application.wsgi
when it comes to the latest command, error occurs:
ModuleNotFoundError: No module named 'fcntl'
How can I solve it?
Is the underlying operating system Windows? fcntl is not available on Windows system and Gunicorn does not work on windows
Run a WSGI web app (like Django) on Windows uing Waitress
Basically all you have to do is replace the gunicorn call with:
waitress-serve --listen=*:8000 myapp.wsgi:application
For typical apps this will give you the same result as running gunicorn. :) Good luck!
The fcntl module is not available on Windows. you should use waitress for http and for https use django-sslserver.
I am trying to deploy a flask app I made to Heroku with success.
The app is generated but I get errors when I push the code to the Heroku repository.
My flask app is inside a module called server.py and the variable is named app.
At first I tried using gunicorn and writing
web: gunicorn server:app
and deplying but no web dynos were up and I get an error stating it is the Procfile file.
Red about it about and saw that Gunicorn is not really working on windows so I tried installing Waitress and deploying without success. this time my profcile was written as all of these (tried several times):
web: waitress-serve --listen=*:8000 server.wsgi:application
web: waitress-serve --listen=*:8000 app.wsgi:application
And so on.
to add a web dyno I should scale it because heroku ps: showes that there is no dynos.
When I try to run heroku ps:scale web=1 I get:
Scaling dynos... !
▸ Couldn't find that process type.
What am i doing wrong?
I was having the same problem. Particularly, waitress works locally in Windows (inside a Procfile.windows file web: waitress-serve index:server, then with heroku CLI heroku local -f Procfile.windows), but failed after Heroku deployment. Workaround for me was to locally test with waitress (like explained), but deploy with gunicorn (web: gunicorn index:server inside Procfile). Let me know if this works for you.
I've been stuck trying to get my simple bottle app starting when deployed on heroku.
After quite some searching and tinkering I've got a setup that works locally, but not on heroku.
In /app.py:
import bottle
import beaker.middleware
from bottle import route, redirect, post, run, request, hook, template, static_file, default_app
bottle.debug(True)
app = beaker.middleware.SessionMiddleware(bottle.app(), session_opts)
...
# app routes etc, no run()
Then in /Procfile:
web: gunicorn app:app --bind="0.0.0.0:$PORT" --debug
Correct me if I misunderstand how gunicorn works, I understand the "app:app" portion as look in the module (=file) called app.py and use whatever is in variable "app" as your WSIG, yes?
I've checked via $ heroku run bash if $PORT is set, seems ok
The "0.0.0.0" IP I've got from other heroku examples, that should anyway accept any IPs server end, no?
Python dependencies seem to get installed fine
I've got this locally running by setting the $POST variable via an .env file for foreman, everything seems working ok on my setup
Based on this SO question I checked $ heroku ps
=== web (1X): `gunicorn app:app --bind="0.0.0.0:$PORT" --debug`
web.1: crashed 2014/12/24 22:43:00 (~ 1m ago)*)
And $ heroku logs shows:
2014-12-24T20:42:59.235657+00:00 heroku[web.1]: Starting process with command `gunicorn app:app --bind="0.0.0.0:23177" --debug`
2014-12-24T20:43:00.434570+00:00 heroku[web.1]: State changed from starting to up
2014-12-24T20:43:01.813679+00:00 heroku[web.1]: State changed from up to crashed
2014-12-24T20:43:01.803122+00:00 heroku[web.1]: Process exited with status 3
Not sure really how I could get better debugging results either. Somehow the Procfile web process just doesn't seem to work / start, but how can I get info on what's breaking?
Anybody got ideas what's going on here?
P.S.: I'm rather new to heroku, python, bottle & gunicorn :O
What version of gunicorn do you use?
gunicorn 19.1 doesn't write errorlog by default. Try gunicorn --log-file=-.
-R is also useful option to investigate error.
Can you try having just web: gunicorn app:app in your Procfile with nothing else?
I'm attempting to setup a generic Pyramid project to work with uWSGI through Cherokee, but constantly get a "no app loaded" error. All the research I've done doesn't really give me much to go on. Anyone have any ideas? Please note that I 'am' using a virtualenv via virtualenvwrapper.
This is from my development.ini
[uwsgi]
socket = 127.0.0.1:2626
master = true
processes = 1
virtualenv = /home/user/.virtualenvs/pyramid/
pythonpath = /home/user/Projects/ConventionMeStatic
And this is the command I've been trying to use to launch it: /usr/bin/uwsgi --ini development.ini --plugin python.
I can post any further details but there have been no other changes made to the project itself.
You have specified a virtualenv and a pytonpath, but you have not specified which app to load.
If you have a single-file app you can load that file with the --wsgi-file option, if you have a deployment.ini file you can use the --paste option as described here
http://projects.unbit.it/uwsgi/wiki/UsePaste
or the --ini-paste shortcuts described in examples section of the uwsgi wiki