0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[メモ] Nginx + Gunicorn の設定 (rhel)

Posted at

前置き

自分のメモ
usキーボードの日本語切り替えが面倒くさいの自分英語で書きます。
気が向いたら日本語に直します。

Nginx install latest version

Installation

Note: http://nginx.org/en/linux_packages.html#RHEL-CentOS
Install yum-utils

yum install yum-utils

Set up repository (/etc/yum.repos.d/nginx.repo)

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

To install nginx

yum install nginx

Configuration

.conf file

/etc/nginx/conf.d/foo.conf
server {
    listen 80;
    server_name foobar;
    
    # Read static files by nginx
    location /static {
        alias /usr/share/nginx/html/static;
    }

    location / {
        proxy_pass http://127.0.0.1:8000/;
    }
}

service command

systemctl start nginx

Python

someday

Gunicorn

Installation

pip install gunicorn

Configuration

/etc/foo/settings.py
wsgi_app = config.wsgi:application
chdir = '/etc/foo/bar'
daemon = False
bind = '127.0.0.1:8000'
workers = 3
timeout = 300
# worker_class = 'gevent'
capture_output = True
accesslog = '/var/log/gunicorn/access.log'
errorlog = '/var/log/gunicorn/error.log'
gunicorn.service
[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=root
Group=root
WorkingDirectory=/etc/foo/bar
ExecStart=/etc/foo/env/bin/gunicorn \
                --config /etc/foo/setting.py

[Install]
WantedBy=multi-user.target

service command

systemctl start gunicorn
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?