Can't connect to django website started on VPS - python

I have tried to start server with Django project like this:
python3.4 manage.py runserver 0.0.0.0:8000
and like this:
python3.4 manage.py runserver my_domain.com:8000
and it starts fine but I can't visit my site. Any ideas what I've done wrong?

The command python manage.py runserver is thought for development purposes.
If you have in mind to have a python (django in this case) website running in a remote server, try having a look at uwsgi.
It's an application server that plays really well with nginx.
Then, it could be possible run your site using the wsgi file in your django project:
uwsgi --http :8000 --module mysite.wsgi
In order to configure your django site, follow this documentation.
Also, if you plan to host more than one website, uwsgi has a emperor mode with slightly different configuration, but really worth for your VPS memory.

Related

Can't find web process procfile error with Windows Heroku

I want to deploy my website which works locally, but runs an error when it tries to have a public instance.
I am on Windows 8.1 and following the official instructions have created a Procfile.windows. It looks like this:
web: python app.py runserver 0.0.0.0:5000
The build works, but then I get this error when I run heroku ps:scale web=1:
Couldn't find that process type (web).
Repo here.
The official tutorial works, so there's definitely proof of concept of this working somehow.
I am on Windows 8.1 and following the official instructions have created a Procfile.windows
Why did you name this file Procfile.windows? The documentation is quite clear:
The Procfile is always a simple text file that is named Procfile without a file extension. For example, Procfile.txt is not valid.
Rename it to Procfile and redeploy.
Once you've got that working, install a WSGI server and use that instead of manage.py runserver, which isn't suitable for production use:
DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through security audits or performance tests. (And that’s how it’s gonna stay. We’re in the business of making Web frameworks, not Web servers, so improving this server to be able to handle a production environment is outside the scope of Django.)
Gunicorn is probably the most common choice, but I don't think it works on Windows so you won't be able to use it in your development environment. uWSGI or Waitress should work.
I installed Waitress and changed my Procfile to
web: waitress-serve --port=$PORT app:app
I also removed the .windows extension, which is meant for local development.
It works fine now!
(My equivalent to "main.py" was "app.py" so you'd likely change this for your needs to {main.py}:app)
Edit your procfile to look like
web: gunicorn --bind 0.0.0.0:$PORT app:app
And your procfile.windows filed as
web: python app.py runserver 0.0.0.0:5000

How to make django globally available

How can I make my Django project accessible via internet?
When I execute the project in Windows OS by typing with a disabled firewall it works and reachable via the internet.
But in Linux OS it does not. I tried the same actions. Executed it by typing and made sure my firewall is disabled
python manage.py runserver 0.0.0.0:8000
The expected result is that project is accessible via the internet like in windows OS
you must deploy your app in one server. I recommend you pay for one VPS like digitalocean. And dont run you app with runserver. Runserver is only for development. Use one wsgi like gunicorn.
If you not want pay for this service. You can use heroku
https://devcenter.heroku.com/articles/deploying-python
I recommend use docker. Docker possibilite you development and deploy same envoriment

How to host Django 1.10 Web Application on WHM via cpanel?

I want to host my Django 1.10 web application on WHM(VPS). for that i have installed Django and another necessary tools on WHM(VPS) by ssh login. and i also have uploaded my Django application code through cpanel in public_html directory.
When i run python manage.py runserver <ip_address:8000> from ssh terminal, i am able to access that application. but when i close the ssh terminal, it terminates all the running process. so could not access application after that.
So, Is there any way that without running python manage.py script i can access Django application?
Any help would be highly appreciated.
Thank you.
Django comes with a built-in development server, it's not really meant to be used when deploying to a remote VPS.
There are some great resources to help you along, but what you're likely going to want to do is deploy your app on a stack using gunicorn or uwsgi as an application server and a web server like Nginx or apache 2 as a reverse proxy.
I personally use Nginx and uwsgi.
There are some great resources explaining how to deploy a Django server. Have a look at this one from digital ocean, it was a great help when I needed to set up a production server correctly: https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-uwsgi-and-nginx-on-ubuntu-16-04
best of luck with it!

Is it normal that the Django site I recently deployed on Apache is always on?

I recently deployed a Django site on a DigitalOcean droplet through Apache. I did python manage.py runserver through ssh and now the Django site is running. However, it stayed on even after the ssh session expired (understandable because it's still running on the remote server) but how do I shut it down if I need to?
Also, due to this, I don't get error messages on the terminal if something goes wrong like I do when I develop locally. What would be a fix for this?
Your question is confusing. If you deployed it with Apache, it's running through Apache and not through runserver. You might have additionally started runserver, but that is not what is serving your site.

Does python manage.py runserver use paster as the server?

A little confused, does python manage.py runserver use the paster web server or is this a django specific server?
It's a custom WSGI server built on BaseHTTPServer and adapted from wsgiref.

Categories

Resources