Reproduced from
Http://blackgu.blogbus.com/logs/171363164.html
Slightly modified
1) Install Flask,uwsgi,nginx
Flask:sudo Apt-get Install Python-flask
Uwsgi:sudo apt-get
install
uwsgi uwsgi-plugin-python
Nginx:sudo Apt-get Install Nginx
2) Create Flask Project
Here is the simplest HelloWorld to create a project catalog: MyApp, which contains the following files:
File name: myapp.py
Code:
From flask import Flask
App = Flask (__name__)
@app. Route ('/')
def hello ():
Return ' Hello world '
if __name__ = = ' __main__ ':
App.run ()
3) configuration Uwsgi
In the MyApp directory you just created, create a UWSGI XML configuration file Myapp_config.xml:
<uwsgi>
<pythonpath>[the root directory of your project]</pythonpath>
<module>[module name, here with myapp]</module>
<callable>[because the app is the portal to start the whole service, so it's app]</callable>
<socket>/tmp/uwsgi.sock</socket> #注: Here the sock file is not a ready-made file, do not need to be created in advance, the runtime will be automatically created, the file name is self-determined, the path can be self-determined
<master/>
<processes>4</processes> #注: Run a few threads, here with 4 threads
<memory-report/>
</uwsgi>
Examples:
<uwsgi>
<pythonpath>/root/workspace_aptana/mytest/src/test/uwsgi</pythonpath>
<module>myapp</module>
<callable>app</callable>
<socket>/tmp/uwsgi.sock</socket>
<master/>
<processes>4</processes>
<memory-report/>
</uwsgi>
3) Configure Nginx
Under the/etc/nginx/sites-available/directory, create a Web file profile site:
server {
Listen 80;
server_name www.myapp.com;
Location/{
Include Uwsgi_params;
Uwsgi_pass Unix:/tmp/uwsgi.sock; #注: The sock file here and the Uwsgi sock file match the same file because Nginx and UWSGI need to interact through this socket
}
}
Or, simply modify the following in the defaut.conf directly:
server {
Listen 8081;
server_name localhost;
Location/{
Include Uwsgi_params;
Uwsgi_pass Unix:/tmp/uwsgi.sock;
}
}
Then use the LN command to create a link to/etc/nginx/sites-enable/, Link's name is also called site, delete the Sites-enable directory under the default link:
sudo ln-s/etc/nginx/sites-available/site/etc/nginx/sites-enabled/( Note: This is ln's lowercase command )
sudo rm/etc/nginx/sites-enabled/default
4) Start deployment
1. Start Uwsgi, command is sudo uwsgi-x myapp_config.xml, will play a lot of words, if not loaded project success can be seen from the information, and then do not close the terminal,
2. Open a new terminal, in the inside start Nginx:sudo/etc/init.d/nginx start, and then in the browser to access the localhost (see the configured nginx in the server listening port, such as the above 8),
3 At this time if the 502 page appears, you can look at the log, my log is in/var/log/nginx/error.log, if the display is sock file because of permissions problems can not be accessed, that is, as long as the chmod command to sock file assigned permissions: chmod 777/ Tmp/uwsgi.sock, then Uwsgi and Nginx reboot again, now visit localhost to see "Hello world! ", ok!
Raspberry Pi Deployment Flask+uwsgi+nginx process