Nginx入门
-
安装
-
下载
wget https://nginx.org/download/nginx-1.22.1.tar.gz
-
解压
tar zxvf nginx-1.22.1.tar.gz
-
进入目录
nginx-1.22.1
-
安装gcc依赖
yum install gcc -y
-
编译参数
./configure --prefix=/usr/local/nginx
--prefix
设置安装目录 -
安装
make && make install
-
安装完成检查是否存在
/usr/local/nginx
目录 -
进入到nginx主目录后,进入
sbin
目录,启动nginx -
查看是否运行成功
-
安装时出现的问题
-
./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre=<path> option.
解决办法:安装pcre
sudo yum install pcre-devel #RHEL/CentOS sudo apt-get install libpcre3-dev #Ubuntu/Debian
参考文章:Nginx configure error: the HTTP rewrite module requires the PCRE library
-
./configure: error: the HTTP gzip module requires the zlib library. You can either disable the module by using --without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using --with-zlib=<path> option.
解决办法
sudo yum install -y zlib zlib-devel
-
启动了但是无法连接
解决办法:关闭防火墙或者放行端口
systemctl stop firewalld firewall-cmd --zone=public --add-port=80/tcp --permanent
-
-
-
启动
Nginx
nginx
启动nginx -s stop
快速停止nginx -s quit
停止,正在进行的连接不受影响nginx -s reload
重新加载配置
-
系统文件配置
vim /usr/lib/systemd/system/nginx.service
[Unit] Description=nginx - web server After=network.target remote-fs.target nss-lookup.target [Service] 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=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s stop ExecQuit=/usr/local/nginx/sbin/nginx -s quit PrivateTmp=true [Install] WantedBy=multi-user.target
systemctl daemon-reload #重新加载配置
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。