centos 7安裝 nginx

1、更新yum

yum update

2、安裝依賴

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

3、進入到 /usr/local/src目錄下載nginx

wget http://nginx.org/download/nginx-1.14.0.tar.gz

4、解壓

tar -zxvf nginx-1.14.0.tar.gz

5、編譯

./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/tem/nginx/client --http-proxy-temp-path=/var/tem/nginx/proxy --http-fastcgi-temp-path=/var/tem/nginx/fcgi --with-http_stub_status_module

6、安裝

make && make install

7、啓動

nginx -c /etc/nginx/nginx.conf

8、如果出現[emerg] getpwnam("nginx") failed 錯誤 執行

useradd -s /sbin/nologin -M nginx
id nginx

9、如果出現 [emerg] mkdir() "/var/temp/nginx/client" failed (2: No such file or directory) 錯誤 執行

mkdir -p /var/tem/nginx/client

10、如果您正在運行防火牆,請運行以下命令以允許HTTP和HTTPS通信:

firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

11、輸入服務器地址,查看是否成功

12、配置nginx開機啓動

切換到/lib/systemd/system/目錄,創建nginx.service文件vi nginx.service

cd /lib/systemd/system
vi nginx.service

輸入內容如下:

[Unit]
Description=nginx 
After=network.target

[Service] 
Type=forking 
ExecStart=/usr/local/src/nginx/sbin/nginx
ExecReload=/usr/local/src/nginx/sbin/nginx reload
ExecStop=/usr/local/src/nginx/sbin/nginx quit
PrivateTmp=true 
   
[Install] 
WantedBy=multi-user.target

其中/usr/local/src爲你的nginx安裝目錄

退出保存文件,然後執行命令:

systemctl enable nginx.service

systemctl start nginx.service 啓動nginx

systemctl stop nginx.service 結束nginx

systemctl restart nginx.service 重啓nginx

最後請求服務器,檢驗是否安裝成功!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章