I use fastcgi to run a django application. The command I use to run it is as follows:
python manage.py runfcgi method=threaded host=127.0.0.1 port=3035
If I input ps -ef|grep python I can see the thread also, but when i use lynx localhost:3035 to open it, I get a 504 gateway timeout.
So instead, now I use
python manage.py runserver 3035
and it runs OK. I don't know the reson. In the past, I use django 1.2 and it was OK.
my server info:
debian5.0, django1.3, python2.6
The FastCGI protocol is different from HTTP protocol. You need to add some layer talking both HTTP and FastCGI protocols, between lynx and devserver. For example nginx w/ FastCGI module configured.
If deploy with nginx, the better choices are gunicorn or uwsgi(supported natively by nginx).
gunicorn:
http://gunicorn.org/run.html
uwsgi
http://projects.unbit.it/uwsgi/wiki/Example
Related
Using this command
python manage.py runserver 0.0.0.0:8000
we can host a Django server locally on any port.So a developer can use reserved and privileged port numbers say
python manage.py runserver 127.0.0.1:80
So, now I am using port 80 defined for the HTTP protocol.
So, why does this not raise any issues and how is this request granted ?
Port 80 has no magical meaning, it is not "reserved" or "privileged" on your server (besides most likely requiring root privileges to access, as others have mentioned). It is just a regular port that was chosen to be a default for http, so you don't have to write google.com:80 every time in your browser, that's it.
If you have no web server running such as apache or nginx which usually listen to that port, then port 80 is up for grabs. You can run django runserver on it, you can run a plain python script listening to it, whatever you like.
You should use a proper server instead of Django's test server such as nginx or apache to run the server in production on port 80. Running something like sudo python manage.py runserver 0.0.0.0:80 is not recommended at all.
I was reading the tutorial provided in
http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html
This very tutorial is a great tutorial. I have been able to configure django server on my raspberry pi raspbian system, on my Ubuntu Desktop too.
Now I am trying to do the same on a Virtual Machine, Ubuntu 16.04, nginx server.
On the line,
uwsgi --socket :8001 --wsgi-file test.py
I get an error saying
invalid request block size 21573 on the terminal
I went through the uwsgi tutorial that said not to use --http for --socket;
Either way I have not been able to get my webserver running. Please help.
Nginx is currently serving a wordpress site on start.
With --socket option you have to use uwsgi module in nginx instead of proxy.
I'm a newcomer to web applications and AWS, so please forgive me if this is the answer is bit trivial!
I'm hosting a python web application on a AWS EC2 server using nginx + uWSGI. This is all working perfectly, except when I terminate my connection (using putty), my uWSGI application stops running, producing a "502 Bad Gateway" error from nginx.
I'm aware of adding the "&" to the uwsgi start up command (below), but that does not work after I close out my connection.
uwsgi --socket 127.0.0.1:8000 -master -s /tmp/uwsgi.sock --chmod-socket=666 -w wsgi2 &
How do I persist my uWSGI application to continue hosting my web app after I log out/terminate my connection?
Thanks in advance!
You'll typically want to start uwsgi from an init script. There are several ways to do this and the exact procedure depends on the Linux distribution you're using:
SystemV init script
upstart script (Ubuntu)
supervisor (Python-based process manager)
For the purposes of my use case, I will not have to reboot my machine in the near future, so Linux's nohup (no hangup) command works perfectly for this. It's a quick and dirty hack that's super powerful.
I am configuring django for using django admin tool, following steps in webpage http://www.ibm.com/developerworks/linux/library/l-django/?S_TACT=105AGX52&S_CMP=cn-a-l
which server did I use,when I type "python manage.py runserver"? apache? or a simple http server in python?
And I have apache 2.2 listening port 80.
You are using Django's development server, which as you say is a simple http server written in Python, and runs in the Python process you start with the "python manage.py runserver" command. Note that this server is not meant for production use. For example, it can handle only one request at a time.
I'm just starting to learn Python and Django and an unable to get the most basic app working. I've setup Python, added python to the Path environment variable, installed Django using install.py script.
I created an app by running the command
django-admin.py startproject my_project
updated the settings.py file for a database
DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = 'mysitedb'
Ran the command
python manage.py syncdb
And finally, started everything up
python manage.py runserver
To this point, everything looks to have run successfully. When I got to view http://localhost:8000/ I get the error "Page not found: /"
I originally installed Django version 1.1, but got the same error, so I removed it and tried the older version 1.0.3. Niether work. Any help would be appreciated.
To complete this question - #artran's answer of changing the port
python manage.py runserver 8001
will work.
When python runs the server, it automatically uses port 8000 (hence http://127.0.0.1:8000/). It uses this port as to not tread on the toes of other applications using localhost ports. However, you may still have an application or service running through this port. As such using port 8001 or any other port you may consider free should work.
To repair this in the future, you need to run a program of which can finger all your ports and determine what application is using the :8000 port.
It sounds like you need to create some apps for your project and set up the urls. As you are just starting you'd be best following the tutorial right through to get a feel for it all.
You probably have ADMIN_MEDIA_PREFIX = "" in your settings. Django intercepts requests to this url and attempts to serve admin media, thus when you make it an empty string, it will attempt to intercept ALL requests, resulting in nothing working.