Linux 安装Nginx

版本区别

常用版本分为四大阵营

Nginx开源版  http://nginx.org/ Nginx plus

商业版  https://www.nginx.com

openresty  http://openresty.org/cn/

Tengine     http://tengine.taobao.org

 

安装步骤

这里是开源版  nginx-1.21.6.tar.gz

1、将tar包上传到linux服务器,解压缩

2、编译安装

./configure
./configure --prefix=/usr/local/nginx --指定安装到/usr/local/nginx目录下

 

如果出现警告或报错

提示1:

checking for OS + Linux 3.10.0-693.el7.x86_64 x86_64 checking for C compiler ... not found ./configure: error: C compiler cc is not found

需要安装gcc

yum install -y gcc

 

 

 

 

 

 提示2

1
2
3
4
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

  

 

 

 需安装perl库

yum install -y pcre pcre-devel

提示3

./configure: error: the HTTP gzip module requires the zlib library. You can either disable the module by using --without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using --with-zlib=<path> option.

 

 

 需安装zlib库

yum install -y zlib zlib-devel

接下来执行 

  make               ##编译

 

 

 

 

  make install    ##安装

安装完后可以看到local目录下已经多了一个nginx目录

 

3、 启动Nginx

进入安装好的目录 /usr/local/nginx/sbin

相关启停命令
./nginx 启动 ./nginx -s stop 快速停止 ./nginx -s quit 优雅关闭,在退出前完成已经接受的连接请求 ./nginx -s reload 重新加载配置

运行 ./nginx就已经启动了

此时在浏览器输入 ip 

 

 显示无法访问此网站

 

 

 关闭防火墙

systemctl stop firewalld.service

关于防火墙

禁止防火墙开机启动 systemctl disable firewalld.service 放行端口 firewall-cmd --zone=public --add-port=80/tcp --permanent 重启防火墙 firewall-cmd --reload

 

刷新网页,出现Welcome to nginx! 表示启动成功

 

创建启动nginx的便捷脚本

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

 脚本内容    路径要对应安装路径

[Unit] Description=nginx - web server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s stop ExecQuit=/usr/local/nginx/sbin/nginx -s quit PrivateTmp=true [Install] WantedBy=multi-user.target

 

 使用此脚本启动nginx

查看当前nginx进程 ps -ef | grep nginx 关闭nginx ./nginx -s stop 使用上述脚本启动nginx systemctl start nginx 查看nginx状态 图中绿色部分 Active: active (running) 则表示启动成功 systemctl status nginx

 

 开机启动

systemctl enable nginx.service

 reboot重启后 ps -ef | grep nginx   列表有nginx表示开机自启动成功

 


__EOF__

作  者Aaron
出  处https://www.cnblogs.com/Williamls/p/16173758.html
关于博主:  谦谦君子 卑以自牧
版权声明:署名 - 非商业性使用 - 禁止演绎,协议普通文本 | 协议法律文本
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!

posted @   LuckinAaron  阅读(179)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
0
0
关注
跳至底部
点击右上角即可分享
微信分享提示