Nginx高併發系列之一——Centos7.x上安裝與配置Nginx


Nginx高併發系列之一——Centos7.x上安裝與配置Nginx

1.linux環境:

Nginx高併發系列之一——Centos7.x上安裝與配置Nginx

2.nginx版本:這裡以1.13.7版本為例子

Nginx高併發系列之一——Centos7.x上安裝與配置Nginx

3.下載nginx包:

<code>[root@joker nginx]# wget http://nginx.org/download/nginx-1.13.7.tar.gz/<code>

4.解壓到相應的文件夾:

<code>mkdir -p /usr/local/nginx/<code>
<code>mv nginx-1.13.7.tar.gz /usr/local/nginx/<code>
<code>cd /usr/local/nginx/<code>
<code>tar -zxvf nginx-1.13.7.tar.gz/<code>
<code>./configure/<code>

如果報錯是因為缺少C++安裝環境,只需要安裝一下即可:

<code>yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel/<code>
<code>./configure/<code>
<code>make/<code>
<code>make install/<code>

默認安裝到/usr/local/nginx目錄下

5.驗證是否安裝完畢:

<code>nginx -v/<code>


Nginx高併發系列之一——Centos7.x上安裝與配置Nginx

6.設置開機啟動

<code>vi /lib/systemd/system/nginx.service/<code>

然後填入一下文本:

[Unit]

Description=nginx - high performance web server

Documentation=http://nginx.org/en/docs/

After=network.target

[Service]

Type=forking

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

說明:其中ExecStart,ExecReload,ExecStop這裡分別為你自己安裝的nginx根目錄,請根據自行安裝的查找到自己的目錄.

查找命令:

<code>whereis nginx/<code>
Nginx高併發系列之一——Centos7.x上安裝與配置Nginx

7.開機自動啟動

<code> systemctl enable nginx/<code>

沒出現八錯即啟動成功

8.運行nginx

常用的命令:

nginx # 運行nginx

nginx -s reload # 重新載入配置文件並運行

nginx -s reopen # 重啟 Nginx

nginx -s stop # 停止 Nginx

***啟動nginx:

<code>nginx/<code>


9.配置文件:

<code>cat /usr/local/nginx/conf/nginx.conf/<code>

根據自行需要進行配置。每次修改完畢刷新配置命令為:

<code>nginx -s reload /<code>
<code>nginx -s reload /<code>

沒有報錯即更新成功

也可以先試用 nginx -t 檢測配置是否有誤再刷新配置。

詳情盡情期待下一篇Nginx文章。感謝關注!


分享到:


相關文章: