Python Web部署笔记四(Nginx)

nginx安装

  1. RHEL-CentOS
  2. installing-a-prebuilt-centos-rhel-package-from-the-official-nginx-repository

$ sudo yum install yum-utils
$ sudo yum update

$ vi /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

$ sudo yum install nginx

$ nginx -v
$ curl -I 127.0.0.1

nginx控制

controlling nginx

nginx -s <signal>

signal: quit reload reopen stop

为应用程序配置nginx

# /etc/nginx/conf.d/awesome.conf
# nginx conf for awesome

server {
    listen 80;
    access_log  /srv/awesome/log/access.log;
    error_log   /srv/awesome/log/error.log;

    location = / {
        proxy_pass      http://127.0.0.1:9000/;
    }

    location ^~ /static/ {
        root    /srv/awesome/www;
    }

    location / {
        proxy_pass      http://127.0.0.1:9000;
        proxy_set_header Host $Host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

}

使用systemctl启动nginx

配置nginx.service
$vi /usr/lib/systemd/system/nginx.service

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
#User=root
#Group=root
Type=forking
PIDFile=/var/run/nginx.pid
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

#Restart=on-failure
#RestartSec=60s

[Install]
WantedBy=multi-user.target

$ systemctl enable nginx.service
$ systemctl start nginx

若因为selinux启动失败解决方法
$ setenforce 0临时关闭selinux

[root@vultr ~]# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      31

[root@vultr ~]# setenforce 0
[root@vultr ~]# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   permissive
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      31

永久关闭:
$ vi /etc/selinux/config

SELINUX=disabled

stackoverflow
官网解决方式
How to Disable SELinux Temporarily or Permanently
Disable SELinux on CentOS 7
Disable SELinux on CentOS 7 / RHEL 7 / Fedora Linux
How to troubleshoot SELinux problems



发表评论:

登录后发表评论

最新评论:

    评论区空空如也~

发布者: superadmin