Since it's a special holiday, I decided to create a Web Framework with Python. I've made a dead copy framework of RoR with PHP before, so this time I'm trying to make it with Python.
Hellow world! First of all, it will not start unless you Hello to World. Greetings are very important. (Mystery) I referred to the following site.
Hello World on EC2 with nginx + uwsgi + python http://qiita.com/chunkof/items/6c9d4b01f0057a9a8de0
However, there seems to be a gap in the description on this site. First, the nginx settings. Set up VirtualHost as follows. I will omit the installation of nginx and the description of the file location.
strangerpy.conf
server{
listen 80;
server_name strangerpy.example.com;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:3031;
}
location = /favicon.ico{
empty_gif;
}
}
Next uwsgi config file
uwsgi.ini
[uwsgi]
master = True
socket = 127.0.0.1:3031
wsgi-file = index.py
stats = 127.0.0.1:9191
logto = uwsgi.log
pidfile = uwsgi.pid
Program source file
index.py
# index.py
# coding:utf-8
import logging
import datetime
import uuid
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
logger = logging.getLogger()
logger.addHandler(handler)
logger.setLevel(logging.INFO)
def main():
# log
logger.info('test-log-dayo')
def application(env, start_response):
main()
start_response('200 OK', [('Content-type', 'text/html')])
str = "<html><head><meta charset='utf-8'><title>Home</title></head><body>Hello World!</body></head>".encode("utf-8")
return [str]
After writing the whole thing, move to the directory where index.py and uwsgi.ini are stored and go to the above Start uwsgi by casting the following spell.
uwsgi --ini uwsgi.ini
I have to write the description of server name resolution in / etc / hosts etc., but I omitted that as well. Because it has nothing to do with this paper.
If you use the URL of http://strangerpy.example.com/ and the browser says "Hello World!", You are successful. Perhaps.
Recommended Posts