I have an Ubuntu 12.04 server setup that currently runs a Ruby on Rails application on a Passenger / Nginx install. I decided to play around with some Python and wrote a small application using Bottle. I would like to deploy this application to my server.
I followed this guide on setting up my server to run Python applications. When I run sudo service uwsgi restart I get the following error message:
Restarting app server(s) uwsgi
[uWSGI] getting INI configuration from
/usr/share/uwsgi/conf/default.ini [uWSGI] parsing config file /etc/uwsgi/apps-enabled/example.net.xml
open("./python_plugin.so"): No such file or directory [core/utils.cline 4700]
!!! UNABLE to load uWSGI plugin: ./python_plugin.so: cannot open shared object file: No such file or directory !!!
Sat Dec 8 18:29:14 2012 - [WARNING] option "app" is deprecated: use the more advanced "mount" option
I really don't know a ton about Python, I have installed the plugins I need via easy_install
Which are:
pymongo
beautifulsoup
bottle
My question is: how do I deploy this simple application to my server?
Thank you
I found out that Passenger will run WSGI apps. I followed the instructions on this post http://kbeezie.com/using-python-nginx-passenger/ and had no trouble getting it working.
It was actually pretty easy in the end.
Here is my adaptor in case anybody else has trouble:
https://github.com/nick-desteffen/astronomy-pics/blob/master/passenger_wsgi.py
Related
This is my first time posting and its a pretty long question.
I'm a beginner and I've decided to learn and use Python and DjangoREST to build my first web application.
Unfortunately, I have a lot of issues that I'm not sure how to get answers to. Querying Google one at a time for each component is giving me answers that sometimes conflicts with another component.
First things first, the following is my project setup:-
OS->Ubuntu 16.04.1
Backend->Python3 and DjangoREST
Webserver->uWSGI and nginx
Database->PostgreSQL
Client Side software->AngularJS(which requires the setup of Node.js and NPM)
Now I installed pip and went through the process of creating a virtualenv and ran a test Django app. I was able to get that done.
When I went through the documentation of uWSGI and Nginx over here http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html, I came across the following line
the web client <-> the web server <-> the socket <-> uwsgi <-> Django
This has me slightly confused. Is there a specific order in which I need to install the software I need? And if yes, could you all tell me the correct order?
Thanks in advance!
This is not actually the order you should install software. This is the communication flow in which you(your browser) connect to the django application on your server.
To make work your application in your server you should do the followings:
First install nginx (reverse proxy server and a web server as well)
Install Gunicorn (wsgi server implementation)
Clone your django project in any directory from your remote git (or simply upload it from local pc)
now run the below command inside the project directory
gunicorn YOUR_PROJECT_NAME.wsgi:application \
--name GIVE_A_NAME_AS_YOUR_WISH \
--worker-connections=1000 \
--threads=3 \
--workers NUM_WORKERS \
--user=USER --group=GROUP \
--bind=SERVER_HOST:ANY_PORT_AS_YOUR_CHOICE (TYPICALLY IT IS 8000)
Point number 4 is enough to run your project in your server. check it in the below link
http://YOUR_HOST_ADDRESS:8000/
Now you can redirect all of your traffic to this application by nginx web server configuration. To do so make a file inside /etc/nginx/conf.d/ naming my_app.conf. inside this file copy paste the below code:
server {
listen 80;
location / {
proxy_pass http://127.0.0.1:8000;
}
}
Hopefully it is okay !
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 want to deploy my Flask application on an Apache server. I have an account on the server, and have been told that "The server can be used to run scripts and web apps written in Python (using django and mod_wsgi)".
I am on Windows, and to transfer files I have to use an FTP client - so I am using WinSCP.
Installing mod_wsgi is not as straightforward as I expected and I cannot get any clear documentation online.
Because the server can already run Python scripts using mod_wsgi does that mean that I just have to create a .wsgi file or do I still need to download it?
I don't know how to go about this.
First you need to check if mod_wsgi is really enabled on the server, then you have to check how your virtual host is configured in apache. There you will find the name you have to give to the wsgi file.
If you have shell access to the server you can do that by using the following commands:
Check mod_wsgi:
sudo apache2ctl -t -D DUMP_MODULES | grep wsgi
Check what name the .wsgi file should have:
sudo grep WSGIScriptAlias /etc/apache2/sites-enabled/yoursite.conf
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'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.