centos7安装nginx1.20.1

2021-06-2811:40:40
评论
2,291 2257字

关闭selinux

sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config  && setenforce 0

# 准备安装文件

yum install -y tar wget vim  gcc pcre-devel openssl-devel zlib-devel GeoIP GeoIP-devel GeoIP-data libunwind-devel google-perftools-devel
wget  https://1314.gift/env/nginx/nginx-1.20.1.tar.gz
tar -zxvf nginx-1.20.1.tar.gz

# 进入安装目录

cd nginx-1.20.1

## configure

./configure \
--prefix=/etc/nginx \
--with-pcre \
--with-http_auth_request_module \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_geoip_module \
--with-mail \
--with-mail_ssl_module \
--with-google_perftools_module \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module

# 编译并安装

make && make install

## make未找到

yum -y install automake autoconf libtool make

# 使systemctl能管理运行nginx服务

cd /etc/nginx/conf
mkdir /data
mkdir /data/nginx
mkdir /data/nginx/logs

## 创建nginx用户

#-g:指定所属的group
#-s:指定shell,因为它不需要登录,所以用/sbin/nologin
#-M:不创建home目录,因为它不需要登录

groupadd nginx
useradd -g nginx -s /sbin/nologin -M nginx

# 生成service文件:

vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx-The High-performance HTTP Server
After=network.target
[Service]
Type=forking
PIDFile=/etc/nginx/logs/nginx.pid
ExecStartPre=/etc/nginx/sbin/nginx -t -c /etc/nginx/conf/nginx.conf
ExecStart=/etc/nginx/sbin/nginx -c /etc/nginx/conf/nginx.conf
ExecReload=/etc/nginx/sbin/nginx -s reload
ExecStop=/etc/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target

# 重新加载服务文件

systemctl daemon-reload

# 运行&自起Nginx服务

systemctl enable nginx && systemctl start nginx

# 放行端口

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --reload

# 找不到nginx

echo "export PATH=$PATH:/etc/nginx/sbin" >>/etc/profile
source /etc/profile

# 常用命令

/etc/nginx/sbin/nginx -v 查看Nginx版本(小v)
/etc/nginx/sbin/nginx -V 查看nginx的配置编译参数(大V)
/etc/nginx/sbin/nginx 启动
/etc/nginx/sbin/nginx -s stop 停止
/etc/nginx/sbin/nginx -s reload 重启
/etc/nginx/sbin/nginx -t 检测语法错误
/etc/nginx/sbin/nginx -V 2>&1 | tr -- - '\n' | grep module # 查看安装了那些模块

# 快捷命令

systemctl start nginx #启动
systemctl stop nginx #停止
systemctl reload nginx #重启
systemctl status nginx #查看服务状态

豌豆日志
  • 本文由 发表于 2021-06-2811:40:40
  • 转载请务必保留本文链接:https://pealog.com/514.html
Centos7 nat转发 系统运维

Centos7 nat转发

学校实验室有台服务器申请了固定的公网IP,能连接外部网络,同时该机器和其它几台内部服务器连接在一个路由器上。需要将该服务器的网络共享给其它内网服务器。进行如下设置即可。 首先,外网服务器有两根网线连接...
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: