https://nginx.org/en/download.html 下载地址(我下载的是1.20.2)
1、首先保证可以连接外网
2、将包拖入opt/nginx
3、安装gcc环境
(如果出现问题可以参考https://www.cnblogs.com/lzxianren/p/4254059.html)
yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
4、加压文件
cd /opt/nginx
tar -zxvf nginx-1.20.2.tar.gz
ls
5、 拷贝文件
mv nginx-1.20.2 /usr/local/nginx
6、切换目录
cd /usr/local/nginx
pwd
7、 配置路径
./configure --prefix=/usr/local/nginx --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --http-scgi-temp-path=/var/temp/nginx/scgi --conf-path=/usr/local/nginx/nginx.conf
8、 补全 nginx 配置目录
mkdir /var/temp/nginx -p
9、编译并安装(在usr/local/nginx目录下)
pwd
make && make install
10、 测试配置与 nginx 是否正常,当出现 successful 即可
ls ./sbin/
./sbin/nginx -t
11、启动 nginx(默认端口是 80)
./sbin/nginx -c nginx.confps -ef | grep nginx
12、 在虚拟机访问nignx(打开火狐浏览器)
http://localhost
13、查看ip、在本机访问
ifconfig
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload
firewall-cmd --query-port=80/tcp
14、重启后可能出现的bug
(可能出现
nginx: [emerg] open() "/var/run/nginx/nginx.pid" failed (2: No suchfile or directory))
可以参考
(57条消息) nginx启动失败,“/var/run/nginx/nginx.pid“ failed (2: No such file or directory) 解决办法_全世界最可爱的小煤球的博客-CSDN博客
(57条消息) nginx启动报错:nginx: [error] open() “/var/run/nginx/nginx.pid“ failed (2: No such file or directory) 的解决_"nginx: [error] open() \"/run/nginx.pid\" failed (_@WanJian的博客-CSDN博客