Centos 7 install Nginx

一.新建yum配置文件
添加:/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

[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

官方给了主线版本和稳定版本的yum地址,生产环境推荐使用稳定版本,来上脚本

rm -rf /etc/yum.repos.d/nginx.repo
touch /etc/yum.repos.d/nginx.repo
cat >> /etc/yum.repos.d/nginx.repo << EOF
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/
gpgcheck=0
enabled=1
EOF

添加nginx 的yum 源后接下来就是安装了
二.安装nginx


yum -y install nginx

三.nginx相关配置
1.系统操作
启动:systemctl start nginx
重启:systemctl restart nginx
状态:systemctl status nginx
自启:systemctl enable nginx

2.涉及目录及配置文件
nginx.conf: /etc/nginx/nginx.conf
user: nginx;
error_log: /var/log/nginx/error.log warn;
pid: /var/run/nginx.pid;
access_log: /var/log/nginx/access.log main;

3.生产注意事项
– 修改 Nginx运行用户组、用户 `/etc/nginx/nginx.conf`
user: [用户]
– 修改 日志存储目录 `/etc/nginx/nginx.conf`
error_log: [New NginxLogDir]/error.log warn;
access_log: [New NginxLogDir]/access.log main;
– 关闭 Nginx 版本输出 `/etc/nginx/nginx.conf` HTTP段
server_tokens off;