Centos7.4安装Nginx1.14.0

安装依赖

yum -y install gcc gcc-c++yum -y install zlib zlib-devel openssl openssl-devel pcre-devel

建立用户及用户组

groupadd -r nginx
# -r 表示创建的是系统组
useradd -s /sbin/nologin -g nginx -r nginx
# -r 表示创建的是系统用户
id nginx
# 即使用其他用户启动nginx, 也必须创建nginx用户和用户组, 否则会出现 nginx: [emerg] getpwnam("nginx") failed 错误

编译和安装

./configure --prefix=/opt/nginx/nginx-1.14.0 --user=nginx --group=nginx --with-http_gzip_static_module --with-pcre --with-http_ssl_module --with-http_flv_module --with-stream --with-stream_ssl_module --with-http_stub_status_module
make
make install

建立latest目录和软链, 方便将来替换为新版本

cd /opt/nginx/
ln -s nginx-1.14.0 latest

配置

将nginx加入系统服务

cd /lib/systemd/system/
vi nginx.service

# 内容

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/opt/nginx/latest/sbin/nginx -t -c /opt/nginx/latest/conf/nginx.conf
ExecStart=/opt/nginx/latest/sbin/nginx
ExecReload=/opt/nginx/latest/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

# 内容结束

systemctl enable nginx.service

打开端口启动服务

firewall-cmd --zone=public --list-all
firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --reload

# 启动nginx
systemctl start nginx

猜你喜欢

转载自www.cnblogs.com/milton/p/9693836.html