centos7.x nginx安裝,並加入系統服務和開啓啓動

 

 

一、安裝nginx

先安裝其依賴軟件,最後安裝nginx。

依賴工具,版本根據需要自己下載,我用的版本:pcre-8.3.7.tar.gz, openssl-1.0.1t.tar.gz, zlib-1.2.8.tar.gz, nginx-1.11.1.tar.gz。

將這些依賴包都複製到/usr/local/文件夾下,進行安裝

 

1. 安裝pcre

方式一、wget http://downloads.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz 。

方拾二、上傳源碼壓縮包,解壓、編譯、安裝 三部曲。

1)、解壓文件, 進入pcre目錄,

2)、./configure 完成後,

3)、執行命令: make && make install

2. 安裝 openssl

下載OpenSSL的地址:
http://distfiles.macports.org/openssl/
1)、解壓文件, 回到 openssl目錄下,

2)、./configure 完成後,

3)、執行命令: make && make install

3. 安裝zlib,下載諮詢查找

1)、解壓文件, 回到 zlib目錄下,

2)、./configure 完成後,

3)、執行命令: make && make install

4. 安裝nginx,從官網下載

1)、解壓文件, 回到 pcre 目錄下,

2)、./configure 完成後,

3)、執行命令: make && make install

5.linux 中 nginx,默認不能訪問的,因爲防火牆問題

(1)關閉防火牆

(2)開放訪問的端口號,80 端口

設置開放端口:

 

firewall-cmd --add-service=http –permanent

firewall-cmd --add-port=80/tcp --permanent

重啓防火牆:

 

firewall-cmd –reload

 

二、加入系統服務並開啓開機啓動

1、編寫啓動腳本,內容如下:

vim /usr/lib/systemd/system/nginx.service

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target


[Service] 
Type=forking
# 路徑對應安裝路徑
Type=forking
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true

[Install] 
WantedBy=multi-user.target

2、使用

systemctl start|stop|reload|restart|status nginx.service
開機自啓:
systemctl enable nginx.service
關閉開機自啓:
systemctl disable nginx.service

 

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