Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
21
Help us understand the problem. What is going on with this article?
@mykysyk@github

CentOS7 + nginx + uWSGI + Flask

More than 5 years have passed since last update.

nginx インストール

shell
yum install epel-release
sed -ri 's/^enabled.*=.*1$/enabled = 0/g' /etc/yum.repos.d/epel.repo
yum install nginx --enablerepo=epel
vi /etc/nginx/nginx.conf
/etc/nginx/nginx.conf
user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log;
pid        /run/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    keepalive_timeout  65;
    index   index.html index.htm;
    include /etc/nginx/conf.d/*.conf;
    server {
        listen       80 default_server;
        server_name  localhost;
        root         /usr/share/nginx/html;
        include /etc/nginx/default.d/*.conf;
        location / {
                include uwsgi_params;
                uwsgi_pass unix:/var/lib/nginx/tmp/uwsgi/uwsgi.sock;
        }
        error_page  404              /404.html;
        location = /40x.html {
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
        }
    }
}
shell
systemctl enable nginx.service
systemctl start  nginx.service
systemctl status nginx.service

FLASKインストール

shell
yum install gcc python-devel
curl https://bootstrap.pypa.io/get-pip.py | python
pip install flask
mkdir -p /var/www/flask/
vi /var/www/flask/index.wsgi
/var/www/flask/index.wsgi
import sys
from flask import Flask
sys.path.append('/var/www/flask')
application = Flask(__name__)
@application.route('/')
def index():
    return 'HelloWorld'

uWSGIインストール

shell
yum install pcre-devel openssl-devel zlib-devel
pip install uwsgi
vi /etc/nginx/uwsgi.ini
/etc/nginx/uwsgi.ini
#http://uwsgi-docs.readthedocs.org/en/latest/Systemd.html
[uwsgi]
socket      = /var/lib/nginx/tmp/uwsgi/uwsgi.sock
python-path = /var/www/flask
wsgi-file   = /var/www/flask/index.wsgi
uid         = nginx
gid         = nginx
processes   = 4
threads     = 2
stats       = 127.0.0.1:9191
shell
vi /etc/systemd/system/uwsgi.service
/etc/systemd/system/uwsgi.service
[Unit]
Description=uWSGI
After=syslog.target

[Service]
ExecStart=/bin/uwsgi --ini /etc/nginx/uwsgi.ini
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all

[Install]
WantedBy=multi-user.target
shell
systemctl enable uwsgi.service
systemctl start  uwsgi.service
systemctl status uwsgi.service

firewalld

shell
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
21
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
21
Help us understand the problem. What is going on with this article?