linux安装nginx-离线安装
copy文章: https://blog.csdn.net/t8116189520/article/details/81909574 (opens new window)
1.安装依赖包
//一键安装上面四个依赖
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
1
2
3
2
3
2.下载并解压安装包
//创建一个文件夹
cd /usr/local
mkdir nginx
cd nginx
//下载tar包 或者把离线包的解压包放到 nginx目录下
wget http://nginx.org/download/nginx-1.13.7.tar.gz
tar -xvf nginx-1.13.7.tar.gz
1
2
3
4
5
6
7
2
3
4
5
6
7
3.安装nginx
//进入nginx目录
cd /usr/local/nginx
//进入目录
cd nginx-1.13.7
//执行命令 考虑到后续安装ssl证书 添加两个模块
./configure --with-http_stub_status_module --with-http_ssl_module
//执行make命令
make
//执行make install命令
make install
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
4.启动nginx服务
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
1
5.配置nginx.conf
# 打开配置文件
vi /usr/local/nginx/conf/nginx.conf
将端口号改成8089(随便挑个端口),因为可能apeache占用80端口,apeache端口尽量不要修改,我们选择修改nginx端口。
将localhost修改为你服务器的公网ip地址。
6.重启nginx
/usr/local/nginx/sbin/nginx -s reload
1
查看nginx进程是否启动:
ps -ef | grep nginx
1
7.若想使用外部主机访问nginx,需要关闭服务器防火墙或开放nginx服务端口,端口为上一步nginx.conf的配置端口:
centOS7关闭防火墙命令: systemctl stop firewalld.service
关闭防火墙会导致服务器有一定风险,所以建议是单独开放服务端口 :
开放80端口:
firewall-cmd --zone=public --add-port=80/tcp --permanent
查询端口号80 是否开启:
firewall-cmd --query-port=80/tcp
重启防火墙:
firewall-cmd --reload
8.设置nginx开机自启
1).先创建开机自启脚本
cd /etc/systemd/system
vi nginx.service
1
2
3
4
2
3
4
nginx.service的内容为
[Unit]
Description=nginx service
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
2).设置开机自启动
//设置开机启动
systemctl enable nginx.service
//启动
systemctl start nginx.service
//重启
systemctl restart nginx.service
//查看状态
systemctl status nginx.service
//停止开机自启
systemctl disable nginx.service
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
systemctl enable nginx
编辑 (opens new window)
上次更新: 2024/01/26, 05:03:22
- 01
- python使用生成器读取大文件-500g09-24
- 02
- Windows环境下 Docker Desktop 安装 Nginx04-10
- 03
- 使用nginx部署多个前端项目(三种方式)04-10