CentOS7 安裝配置 nginx

安裝 nginx 所需環境

1.gcc 安裝:

shell> yum install gcc-c++

2.PCRE pcre-devel 安裝:

shell> yum install -y pcre pcre-devel

3.zlib 安裝:

shell> yum install -y zlib zlib-devel

4.OpenSSL 安裝

shell> yum install -y openssl openssl-devel

下載 nginx

下載地址:http://nginx.org/en/download.html

開始安裝

1.將下載好的文件 nginx-1.15.1.tar.gz 上傳到 CentOS 服務器 /home/service 目錄

2.解壓文件 nginx-1.15.1.tar.gz

shell> cd /home/service
shell> tar -xzvf nginx-1.15.1.tar.gz

3.安裝(依次執行如下命令):

shell> cd /home/service/nginx-1.15.1
shell> ./configure --prefix=/home/service/nginx
shell> make
shell> make install

4.啓動 nginx

shell> /home/service/nginx/sbin/nginx

5.檢測 nginx 配置文件是否正確

shell> /home/service/nginx/sbin/nginx -t

6.重啓 nginx 服務

shell> /home/service/nginx/sbin/nginx -s reload

7.配置文件所在目錄

/home/service/nginx/conf/nginx.conf

8.創建軟鏈接

shell> ln -s /home/service/nginx/conf/nginx.conf /home/conf/nginx/

9.開放 80 端口

shell> firewall-cmd --zone=public --add-port=6379/tcp --permanent
shell> firewall-cmd --reload	

nginx 配置開機啓動

1.在系統服務目錄裏創建nginx.service文件

shell> vi /lib/systemd/system/nginx.service

2.文件內容如下(注意替換目錄)

[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/home/service/nginx/sbin/nginx
ExecReload=/home/service/nginx/sbin/nginx -s reload
ExecStop=/home/service/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

3.設置開機啓動

shell> systemctl enable nginx.service

4.其他命令

1> 啓動nginx服務
shell> systemctl start nginx.service
2> 設置開機自啓動
shell> systemctl enable nginx.service
3> 停止開機自啓動
shell> systemctl disable nginx.service
4> 查看服務當前狀態
shell> systemctl status nginx.service
5> 重新啓動服務
shell> systemctl restart nginx.service
6> 查看所有已啓動的服務
shell> systemctl list-units --type=service
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章