1、到官網上下載穩定版本的nginx源碼包。nginx1.12.2官網下載地址 2、編譯安裝
安裝之前先要安裝openssl-devel 、pcre-devel 、zlib-devel 、gcc容器等依賴。否則編譯的時候出現下面的結果:pcre library is not used.
[root@bgsbtsp0010-dqf software]# tar -xf nginx-1.12.2.tar.gz[root@bgsbtsp0010-dqf software]# cd nginx-1.12.2# --prefix 指定安裝路徑# --user=nginx --group=nginx 指定work進程啟動的使用者# --error-log-path=/usr/local/nginx/error.log 指定日誌的位置# --pid-path 指定進程號的位置# --with-debug 指定日誌等級# --http-log-path 指定訪問日誌位置[root@bgsbtsp0010-dqf nginx-1.12.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --error-log-path=/usr/local/nginx/error.log --pid-path=/usr/local/nginx/nginx.pid --http-log-path=/usr/local/nginx/access.log --with-debug[root@bgsbtsp0010-dqf nginx-1.12.2]# make && make install
[root@bgsbtsp0010-dqf nginx-1.12.2]# cd /usr/local/nginx#啟動nginx 切記在啟動之前需要建立nginx使用者,否則會報錯。[root@bgsbtsp0010-dqf nginx]# ./sbin/nginx
如下圖所示:可以看到nginx的master進程和work進程。主進程是root使用者,work進程是nginx使用者起的。error.log,nginx.pid,access.log的位置都是上面指定的固定位置。
我們編輯conf/nginx.conf設定檔,按照如下的配置,然後我們重新載入。
[root@bgsbtsp0010-dqf nginx]# cat conf/nginx.conf#user nobody;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 9011; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }#這裡是自己加了一個server,可以在頁面中載入wyl.html頁面.server { listen 9012; server_name localhost; location / { root html; index wyl.html; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }}
重新載入nginx
[root@bgsbtsp0010-dqf nginx]# ./sbin/nginx -s reload
3、驗證部署 我們可以看到nginx已經部署成功,下面我們自己添加了一個server,修改連接埠,reload之後可以看到helloword的頁面
[root@bgsbtsp0010-dqf nginx]# ./sbin/nginx -s reload