在CentOS 7系统上部署NGINX

一、添加YUM源文件

/etc/yum.repos.d/nginx.repo

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

二、安装Nginx

yum -y nginx

三、系统操作

启动:systemctl start nginx
重启:systemctl restart nginx
状态:systemctl status nginx
自启:systemctl enable nginx
  • 涉及目录及配置文件
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;

生产注意事项

- 修改 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;
```