CentOS 7安装Nginx

1.虚拟机网络模式改为桥接,ip地址改为静态
可以在网上查阅

2. 关闭防火墙
停止防火墙服务

systemctl stop firewalld.service

关闭开机自启

systemctl disable firewalld.service

3. 安装nginx依赖

这里一定要安装好,不然下面会报错,错误为nginx c compiler cc is not found.

yum -y install gcc-c++ pcre-devel zlib-devel openssl-devel

4. 安装wget

yum -y install wget

5. 安装nginx
下载源码包

wget http://nginx.org/download/nginx-1.17.2.tar.gz

解压

tar -zxvf nginx-1.17.2.tar.gz

进入解压出来的文件夹

cd nginx-1.17.2

预编译

./configure --with-http_ssl_module --prefix=/usr/local/nginx

安装

make && make install

6. 修改环境变量
编辑环境变量配置文件

vi /etc/profile

在空白处输入:

PATH=$PATH:/usr/local/nginx/sbin
export PATH

保存文件后刷新

source /etc/profile

7. 修改端口
编辑nginx配置文件

vi /usr/local/nginx/conf/nginx.conf

将listen 80改成如图所示的listen 8080
8. 使用systemctl控制nginx
创建systemctl服务文件

vi /usr/lib/systemd/system/nginx.service

将以下内容输入:

[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.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 stop

[Install]
WantedBy=multi-user.target

保存,使文件生效:

systemctl daemon-reload

然后就可以使用如下命令进行控制:

启动nginx服务:
systemctl start nginx.service
设置开机自启动:
systemctl enable nginx.service
停止开机自启动:
systemctl disable nginx.service
查看服务当前状态:
systemctl status nginx.service
重新启动服务:
systemctl restart nginx.service

9.启动nginx,并设为开机自启

systemctl start nginx.service
systemctl enable nginx.service

10. 访问nginx

在浏览器中输入“当前CentOS的ip:8080”,如192.168.1.1:8080

如果出现下面图片,就说明安装成功了。

å¨è¿éæå¥å¾çæè¿°

评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

宋文轩

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值