编译安装nginx
nginx安装包下载地址:http://nginx.org/en/download.html
1.下载nginx并且上传服务器
2.解压tar包
tar -zxvf nginx-1.20.1.tar.gz
3.编译配置
在nginx用户下编译nginx,设置nginx的编译安装目录为/home/nginx,临时目录为/home/nginx/tmp
./configure --prefix=/home/nginx \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_degradation_module \
--with-http_v2_module \
--with-http_ssl_module \
--http-client-body-temp-path=/home/nginx/tmp/http-client-body-temp \
--http-proxy-temp-path=/home/nginx/tmp/http-proxy-temp \
--http-fastcgi-temp-path=/home/nginx/tmp/http-fastcgi-temp \
--http-uwsgi-temp-path=/home/nginx/tmp/http-uwsgi-temp \
--http-scgi-temp-path=/home/nginx/tmp/http-scgi-temp
make && make install
4.创建bin并且创建启动停止nginx脚本
1.启nginx脚本 start.sh
#!/bin/sh
cd ${HOME}/sbin
./nginx
[ "$?" -eq "0" ] && echo "nginx start success!"
2.停nginx脚本 stop.sh
#!/bin/sh
cd ${HOME}/sbin
./nginx -s stop
[ "$?" -eq "0" ] && echo "nginx stop success!"
3.重启nginx脚本 restart.sh
#!/bin/sh
cd ${HOME}/sbin
./nginx -s reload
[ "$?" -eq "0" ] && echo "nginx restart success!"
4.脚本赋权
cd ~/bin
chmod u+x *.sh
5. 创建临时tmp目录存储临时文件并且修改nginx.conf配置文件,监听端口为8080
6.启动使用默认配置启动nginx
cd ~/bin
./start.sh
7.测试
输入搭建主机的ip:port/index.html
即可查看nginx搭建完成
8.防火墙相关补充
linux上面可能开启了防火墙
1.查看开放的端口号
firewall-cmd --list-all
查看所有防火墙开放端口
2.设置开放的端口号
firewall-cmd --add-service=http --permanent
sudo firewall-cmd --add-port=80/tcp --permanent
3.重启防火墙
firewall-cmd -reload