Centos7.4安裝Nginx1.14.0
阿新 • • 發佈:2018-09-24
run and perm load bin server permanent net 必須
安裝依賴
yum -y install gcc gcc-c++yum -y install zlib zlib-devel openssl openssl-devel pcre-devel
在Ubuntu 下, 對應openssl-devel的包是 libssl-dev
建立用戶及用戶組
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
Centos7.4安裝Nginx1.14.0