nginx的安装

1、环境安装

以下命令按顺序安装即可,成功之后进行下一步操作;

yum install gcc-c++
yum -y install pcre*
yum -y install openssl*
2、上传压缩包

压缩包上传到虚拟机的根目录下的usr下的local,即 /usr/local

cd /usr/local/
3、解压压缩包
tar -zxvf nginx-1.9.9.tar.gz 
4、进入nginx目录
cd nginx-1.9.9
5、设置安装目录

设置nginx的安装目录 /usr/local/nginx

./configure --prefix=/usr/local/nginx 
6、编译、安装

到安装目录下进行编译和安装,以下命令任选其一;

make && make install

安装Iptables管理工具&&启动Iptables&&设为Iptables开机自启&&清空Iptables规则&&保存Iptables默认规则,安装完成之后提示如下;

完毕! Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service. iptables: Saving firewall rules to /etc/sysconfig/iptables:[ 确定 ]

yum -y install iptables-services && systemctl start iptables && systemctl enable iptables&& iptables -F && service iptables save 
7、启动nginx服务并查看服务

到/usr/local/nginx/sbin/目录下进行进程的启动

切换目录:cd /usr/local/nginx/sbin/
启动进程:./nginx
查询:ps -ef | grep nginx
7.1、nginx操作常用命令

进入 nginx 目录中: cd /usr/local/nginx/sbin 才能操作

关闭命令:./nginx -s stop
查看版本号:./nginx   -v
重新加载nginx配置文件:./nginx -s reload

如启动成功提示如下:

root 107055 1 0 16:10 ? 00:00:O0 nginx: master process ./nginx nobody 107056 107055 0 16:10 ? 00:00:00 nginx: worker process root 107303 96623 0 16:10 pts/0 00:00:00 grep --color=auto nginx

8、释放端口号

防火墙释放nginx所需的80端口号,并重启防火墙,再次查看端口号是否释放成功;端口号释放成功,提示【success】

释放端口号:firewall-cmd --zone=public --add-port=80/tcp --permanent
重启防火墙:systemctl restart firewalld.service
关闭防火墙:systemctl stop firewalld
防火墙自启:systemctl enable firewalld
防火墙不自启:systemctl disable firewalld
查看开放的端口(简单查询):firewall-cmd --list-ports
查看开放的端口(详细查询):firewall-cmd --list-all
9、安装成功

浏览访问http://安装nginx的虚拟机IP:80,提示如下及安装成功

Welcome to nginx!

If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.

For online documentation and support please refer to nginx.orgCommercial support is available at nginx.com.

Thank you for using nginx.

10、nginx设置开机自启

随后开始设置开机自启,编辑etc文件

vi /etc/rc.d/rc.local

在最后一行加入nginx对应的路径,保存退出

/usr/local/nginx/sbin/nginx

设置完毕后需要给文件添加可执行权限,添加后可看到字体【rc.local】变绿

cd /etc/rc.d
chmod  777  rc.local
ll

最后一步,使用reboot重启,使用 ps -ef 检查是否成功开机自启。如图显示自启成功

ps -ef | grep nginx

如启动成功提示如下:

[rootalocalhost -]# ps -ef l grep nginx

root 9948 1 0 16:10 ? 00:00:00 nginx: naster process /usr/local/nginx/sbin/nginx nobody 107056 107055 0 16:10 ? 00: 00: 00 nginx: worker process root 107303 96623 0 16:10 pts/0 00:00:00 grep --color=auto nginx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值