redhat安装nginx

本文详细介绍了两种在Linux系统中安装Nginx的方法,包括使用YUM仓库管理和从源代码编译安装,同时提及了配置参数和可能出现的问题解决方法。
摘要由CSDN通过智能技术生成

Install Method 1: Use repo file to install nginx

No.

Steps

Commands

1Configure nginx repo file

#vim /etc/yum.repos.d/nginx.repo

add below content into this repo and rename epel.repo if have

repo file====>

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo            
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

2Clean yum cache

#yum clean all

#yum makecache

3Install nginx#yum install nginx -y 
4Check version t0 verify install successfully#nginx -v
5Start nginx service#systemctl start nginx
6Check nginx service status

#systemctl status nginx

configuration under /etc/<nginx service>/conf.d should be included in NGINX configuration

Install Method 2: Use package to install nginx

No.

Steps

Commands

1Install related dependencies

#yum install gc gcc-c++ automake pcre pcre-devel zlib zlib-devel open openssl-devel

2Download latest nginx package#wget http://nginx.org/download/nginx-1.21.6.tar.gz
3Uncompressed the package#tar -zxvf nginx-1.21.6.tar.gz
4Configure nginx

#cd nginx-1.21.6/

#./configure --with-http_ssl_module --with-http_v2_module --with-stream

--with-http_ssl_module # 配置HTTPS时使用
--with-http_v2_module # 配置GOLANG语言时使用
--with-stream # 启用TCP/UDP代理服务

5Compile and Install

make && make install

6Add niginx into PATH

#vi /etc/profile

#add below line

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


#source /etc/profile

7Add into system management

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

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
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

[Install]
WantedBy=multi-user.target

8Re-load system service and start nginx

#systemctl daemon-reload

#systemctl start nginx

9Check nginx service status

#systemctl status nginx

configuration under /etc/<nginx service>/conf.d should be included in NGINX configuration

client_max_body_size         5G;
client_header_timeout        600s;
client_body_timeout          600s;
ssl_session_cache            shared:SSL:1m;
ssl_session_timeout          5m;


For method 1, If the following error occurs, please replace $releasever to the host os-release version. eg. The host OS is rhel7.9, change the $releasever to 7 in the yum repo file nginx.repo

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值