Nginx 配置

Nginx 功能说明与配置说明.

理论基础

Nginx服务安装启动

  1. 官网下载Nginx直接解压 wget http://nginx.org/download/nginx-1.20.2.tar.gz tar -zxvf nginx-1.20.2.tar.gz
  2. cd nginx
  3. ./configure --prefix=/usr/local/nginx
  4. make
  5. make install

运维

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf启动

自启动:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target

[Service]
#User=nginx
#Group=nginx
LimitCORE=infinity
LimitNOFILE=100000
LimitNPROC=100000
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

systemctl daemon-reload
systemctl restart nginx.service

80 443 端口需要root权限,要用其他权限启动要做些调整。

错误

./configure: error: the HTTP rewrite module requires the PCRE library.
安装pcre-devel解决问题
yum -y install pcre-devel

./configure: error: the HTTP gzip module requires the zlib library.
安装zlib-devel解决问题
yum install -y zlib-devel

cp: ‘conf/koi-win’ and ‘/usr/local/nginx/conf/koi-win’ are the same file
make[1]: * [install] Error 1
make[1]: Leaving directory `/usr/local/nginx’
make: *
[install] Error 2

解决办法:就是你把nginx的待安装文件放在了nginx的默认安装路径上,把tar包 放到除了 /usr/local 目录的其他路径

其他