Nginx部署

Nginx在线/离线部署

在线安装

# 安装所需环境
[root@nginx data]# yum install -y openssl-devel pcre-devel

# 解压
[root@nginx data]# tar zxf nginx-1.24.0.tar.gz 

# 创建工作目录
[root@nginx data]# mkdir -p /apps/nginx

# 安装
[root@nginx data]# cd nginx-1.24.0/
[root@nginx nginx-1.24.0]# ./configure --prefix=/apps/nginx  --with-http_stub_status_module --with-http_ssl_module  --with-pcre  --with-file-aio  --with-http_gzip_static_module
[root@nginx nginx-1.24.0]# make && make install

# 查看结果
[root@nginx nginx-1.24.0]#  /apps/nginx/sbin/nginx -V
nginx version: nginx/1.24.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/apps/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre --with-file-aio --with-http_gzip_static_module
[root@nginx nginx-1.24.0]# cd /apps/nginx/

# 启动;并查看启动结果
[root@nginx nginx]#  ./sbin/nginx

# 访问测试
[root@nginx nginx]# curl 127.0.0.1:80

离线安装

准备工作

# 准备离线安装包
nginx:http://nginx.org/en/download.html (版本:nginx-1.24.0 tar.gz)
pcre:https://sourceforge.net/projects/pcre/files/pcre/(版本:pcre-8.40.tar.gz)
zlib:http://www.zlib.net/(版本:zlib-1.3.1.tar.gz)
oppenssl:https://www.openssl.org/source/(版本:openssl-3.2.1.tar.gz)
-----------------------------------------------------------------------------------
[root@nginx data]# ls
nginx-1.24.0.tar.gz  openssl-3.2.1.tar.gz  pcre-8.40.tar.gz  zlib-1.3.1.tar.gz

# 准备工作目录
[root@nginx ~]# mkdir -p /data/unit/{pcre,zlib,openssl,nginx} && cd /data

第一步:安装PCRE

[root@nginx data]# tar -zxvf pcre-8.40.tar.gz
[root@nginx data]# cd pcre-8.40/
[root@nginx pcre-8.40]# ./configure --prefix=/data/unit/pcre
[root@nginx pcre-8.40]# make && make install

第二步:安装zlib

[root@nginx data]# tar -zxvf zlib-1.3.1.tar.gz
[root@nginx data]# cd zlib-1.3.1/
[root@nginx zlib-1.3.1]# ./configure --prefix=/data/unit/zlib
[root@nginx zlib-1.3.1]# make && make install

第三步:安装openssl

[root@nginx data]# tar -zxvf openssl-3.2.1.tar.gz
[root@nginx data]# cd openssl-3.2.1/
[root@nginx openssl-3.2.1]# ./config --prefix=/data/unit/openssl --shared
[root@nginx openssl-3.2.1]# make && make install


# 出现安装失败问题
[root@nginx openssl-3.2.1]# ./config --prefix=/data/unit/openssl --shared
Can't locate IPC/Cmd.pm in @INC (@INC contains: /data/openssl-3.2.1/util/perl /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 . /data/openssl-3.2.1/external/perl/Text-Template-1.56/lib) at /data/openssl-3.2.1/util/perl/OpenSSL/config.pm line 19.
BEGIN failed--compilation aborted at /data/openssl-3.2.1/util/perl/OpenSSL/config.pm line 19.
Compilation failed in require at /data/openssl-3.2.1/Configure line 23.
BEGIN failed--compilation aborted at /data/openssl-3.2.1/Configure line 23.
# 解决方法
[root@nginx openssl-3.2.1]# yum install perl-IPC-Cmd

第四步:安装nginx

[root@nginx data]# tar -zxvf nginx-1.24.0.tar.gz 
[root@nginx data]# cd nginx-1.24.0/
[root@nginx nginx-1.24.0]# ./configure --prefix=/data/nginx \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-pcre=/data/pcre-8.40 \
--with-zlib=/data/zlib-1.3.1 \
--with-openssl=/data/openssl-3.2.1 \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-pcre \
--with-file-aio \
--with-http_gzip_static_module
[root@nginx ~]# cd /data/nginx/sbin/
[root@nginx sbin]# ./nginx 

# 查看结果
[root@nginx sbin]# curl 127.0.0.1:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

启动方式

[root@nginx ~]# cd /data/nginx/sbin/
./nginx	# 启动服务
./nginx -s reload            # 重新载入配置文件
./nginx -s reopen            # 重启 Nginx
./nginx -s stop              # 停止 Nginx
-----------------------------------------------------------------------------------
# 添加启动文件即可通过systemctl命令来启动nginx
[root@bogon conf]# vi /lib/systemd/system/nginx.service
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/data/nginx/logs/nginx.pid
ExecStartPre=/data/nginx/sbin/nginx -t
ExecStart=/data/nginx/sbin/nginx
ExecReload=/data/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target

# 重载systemctl服务
[root@nginx sbin]# systemctl daemon-reload
-----------------------------------------------------------------------------------

# 检查配置文件
[root@nginx nginx]# /data/nginx/sbin/nginx -t
nginx: the configuration file /data/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /data/nginx/conf/nginx.conf test is successful
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值