安装
Install the prerequisites:
yum install yum-utils
To set up the yum repository, create the file named /etc/yum.repos.d/nginx.repo
with the following contents:
[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
By default, the repository for stable nginx packages is used. If you would like to use mainline nginx packages, run the following command:
yum-config-manager --enable nginx-mainline
To install nginx, run the following command:
yum -y install nginx
When prompted to accept the GPG key, verify that the fingerprint matches 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62, and if so, accept it.
启动:
service nginx start
守护:
systemctl enable nginx
systemctl start nginx
systemctl restart nginx
systemctl stop nginx
systemctl disable nginx
配置文件
程序配置文件:/etc/nginx/nginx.conf
默认配置文件:/etc/nginx/conf.d/default.conf
配置文件目录:/etc/nginx/conf.d/
如果要用反代:
在/etc/nginx/nginx.conf
文件的http
字段加入:
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
安装好后删除repo
mv /etc/yum.repos.d/nginx.repo /etc/yum.repos.d/nginx.repo.b
更详细配置参考简书