openEler离线安装nginx

1.场景描述
项目要部署到新的服务器上,需要安装nginx,刚好安全部门通知了nginx存在安全漏洞(Nginx整数溢出漏洞,nginx1.13.2之后的版本无问题),就下载最新的nginx进行了安装,介绍下在线与离线安装nginx吧,其他关于nginx两篇博客:nginx实战操作(常用命令及配置)与一台服务器通过nginx配置多个域名(80端口)

2. 问题解决
其实所谓的在线安装与离线安装,主要是安装nginx的依赖包,因为nginx是c语言编写的,需要安装些特殊的依赖,常用的cenos中一般都没带。

2.1 在线安装,使用yum安装
yum install gcc-c++ (选择y回车)
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel

2.2 离线安装,下载对应包
2.2.1 下载
wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gz
wget https://zlib.net/zlib-1.2.13.tar.gz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz  或者https://search.grilime.com/?14&n=101&q=pcre-8.40.tar.gz 或者 https://nchc.dl.sourceforge.net/project/pcre/pcre/8.45/pcre-8.45.zip

2.2.2 解压及安装
tar zxvf openssl-fips-2.0.10.tar.gz
cd openssl-fips-2.0.10
./config && make && make install

tar zxvf pcre-8.40.tar.gz
cd pcre-8.40
./configure && make && make install
tar zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure && make && make install

2.3 安装nginx
2.3.1 下载最新nginx
http://nginx.org/en/download.html, 目前最新版本是:1.17.2

2.3.2 安装nginx
(1)上传tar包到:/usr/local

(2)安装命令:

cd /usr/local
tar zxvf nginx-1.17.2.tar.gz
cd nginx-1.17.2/
./configure && make && make install

(3)验证安装是否成功

whereis nginx
1
2.3.3 启动nginx
(1)启动命令

/usr/local/nginx/sbin
./nginx

(2)验证是否启动成功

ps -ef|grep nginx

说明: 会有两个进程,一个master进程,一个worker进程。

 

启动服务,检查运行情况:

[root@openEulerOS nginx-1.21.6] cd /usr/local/nginx/sbin/
[root@openEulerOS sbin] ll
total 4.5M
-rwx------ 1 root root 4.5M Mar 2 14:08 nginx
[root@openEulerOS sbin] ./nginx
[root@openEulerOS sbin]
[root@openEulerOS sbin] ps -ef | grep nginx
root 5729 1 0 14:12 ? 00:00:00 nginx: master process ./nginx
nobody 5730 5729 0 14:12 ? 00:00:00 nginx: worker process
root 5746 2938 0 14:13 pts/0 00:00:00 grep --color=auto nginx

. 修改运行用户nobody:

[root@openEulerOS sbin] cd /usr/local/nginx/conf/
[root@openEulerOS conf] ll
total 68K
-rw------- 1 root root 1.1K Mar 2 14:08 fastcgi.conf
-rw------- 1 root root 1.1K Mar 2 14:08 fastcgi.conf.default
-rw------- 1 root root 1007 Mar 2 14:08 fastcgi_params
-rw------- 1 root root 1007 Mar 2 14:08 fastcgi_params.default
-rw------- 1 root root 2.8K Mar 2 14:08 koi-utf
-rw------- 1 root root 2.2K Mar 2 14:08 koi-win
-rw------- 1 root root 5.3K Mar 2 14:08 mime.types
-rw------- 1 root root 5.3K Mar 2 14:08 mime.types.default
-rw------- 1 root root 2.6K Mar 2 14:08 nginx.conf
-rw------- 1 root root 2.6K Mar 2 14:08 nginx.conf.default
-rw------- 1 root root 636 Mar 2 14:08 scgi_params
-rw------- 1 root root 636 Mar 2 14:08 scgi_params.default
-rw------- 1 root root 664 Mar 2 14:08 uwsgi_params
-rw------- 1 root root 664 Mar 2 14:08 uwsgi_params.default
-rw------- 1 root root 3.6K Mar 2 14:08 win-utf
[root@openEularOS conf] vi nginx.conf

按【i】键进入输入模式,将nobody改为root,之后按Esc进入底栏模式,输入 :wq 保存修改并退出vi编辑器,配置修改完成。此时可以通过重新启动nginx服务达到对外访问的效果

 参考:https://www.cnblogs.com/zhangruifeng/p/16335780.html

、启动Nginx(直接用默认配置启动测试即可)

cd /usr/local/nginx/sbin
./nginx

3.2、开放端口

开放nginx默认使用的80端口,并重启防火墙

# 开放80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
# 立即生效
firewall-cmd --reload

设置nginx开机自启

/etc/systemd/system目录创建一个启动脚本

vi /etc/systemd/system/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

  

然后执行

# 查找nginx端口
ps -ef|grep nginx
# 先停止nginx
kill -9 xxx
# 必须先执行这个
systemctl daemon-reload
# 开机自启
systemctl enable nginx
# 启动nginx
systemctl start nginx
 
#设置开机自启动
systemctl enable nginx 
 
#停止开机自启动
systemctl disable nginx
 
#查看服务当前状态 
systemctl status nginx
 
#重新启动服务
systemctl restart nginx   
 
#查看所有已启动的服务 
systemctl list-units --type=service 

原文链接: https://www.cnblogs.com/Amos-Turing/p/17133605.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    openEler离线安装nginx

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/319000

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月24日 下午3:07
下一篇 2023年2月24日 下午3:08

相关推荐