当前系统Centos7.4,关闭selinux,关闭防火墙(或自行设置)
1、配置好yum源,安装依赖
yum install wget gcc gcc-c++ pcre pcre-devel openssl openssl-devel zlib zlib-devel
|---|------------------------------------------------------------------------------------| | 1 | yum install wget gcc gcc-c++ pcre pcre-devel openssl openssl-devel zlib zlib-devel |
2、创建nginx启动用户
useradd -s /bin/false -M www
|---|------------------------------| | 1 | 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
|---------|----------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 | 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
|-------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 | ./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/
|---|-----------------------------------------------------| | 1 | ln -sv /usr/local/nginx/sbin/nginx /usr/local/sbin/ |
6、设置systemctl
vi /usr/lib/systemd/system/nginx.service
|---|------------------------------------------| | 1 | 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
|----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 9 10 11 12 | [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
|---|-----------------------| | 1 | systemctl start nginx |