当前系统Centos7.4,关闭selinux,关闭防火墙(或自行设置)
1、配置好yum源,安装依赖
yum install wget gcc gcc-c++ pcre pcre-devel openssl openssl-devel zlib zlib-devel
2、创建nginx启动用户
useradd -s /bin/false -M www
3、下载解压nginx
cd /usr/local/src/
wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar zxf nginx-1.12.2.tar.gz
cd /usr/local/src/nginx-1.12.2
4、编译nginx
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module
make
make install
5、添加环境变量
ln -sv /usr/local/nginx/sbin/nginx /usr/local/sbin/
6、设置systemctl
vi /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
7、启动nginx
systemctl start nginx
8、最后访问http://IP即可看到nginx欢迎页