1. 程式人生 > >nginx代理伺服器的配置

nginx代理伺服器的配置

在剛剛安裝的linux下安裝配置nginx,從開始到結束的過程

  1. 下載壓縮包
    http://www.nginx.org/ 可按照自己需要的安裝,我下載的是nginx-1.13.3.tar.gz
    接下來開始解壓縮
[root@localhost nginx]# tar -xf nginx-1.0.10.tar.gz   
[root@localhost nginx]# cd nginx-1.0.10  
[root@localhost nginx]# ./configure  

配置過程發生錯誤,,,

......
......

./configure: error: the HTTP rewrite module requires the
PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre=<path> option. [root@localhost nginx]#

原因是因為:缺少PCRE庫(perl擴充套件:正則表示式),如果缺少此庫,nginx無法支援HTTP中的URL重寫功能。
如果可以,建議用:

# yun install -y pcre-devel 
                                #直接安裝此庫;

顯示:
    ......
    ......

    Complete!
表示安裝成功。

之後接著開始配置nginx環境,但是在配置開始之前先建立一個使用者,用於配置此nginx的使用者

#useradd -r nginx

然後開始配置設定:

./configure --prefix=/usr/etc/nginx/nginx_configure/nginx --conf-path=/usr/etc/nginx/nginx_configure/n
ginx.
conf --user=nginx --group=nginx --error-log-path=/usr/etc/nginx/nginx_configure/error.log --http-log-path=/usr/etc/nginx/nginx_configure/access.log --pid-path=/usr/etc/nginx/nginx_configure/nginx.pid --lock-path=/usr/etc/nginx/nginx_configure/nginx.lock --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_mp4_module --http-client-body-temp-path=/usr/etc/nginx/nginx_configure/client --http-proxy-temp-path=/usr/etc/nginx/nginx_configure/proxy --http-fastcgi-temp-path=/usr/etc/nginx/nginx_configure/fastcgi --http-uwsgi-temp-path=/usr/etc/nginx/nginx_configure/uwsgi

這是一部分的配置檔案目錄及快取目錄,放在一個資料夾下方便移植,但是一如既往的出現錯誤,這是配置之後的遇到的錯誤

......
......
......

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.

根據顯示,是少了openssl
解決方法:

# yum -y install openssl openssl-devel

安裝此包,便解決問題啦,。

接下來再次執行nginx配置過程,
出現:

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

  nginx path prefix: "/usr/etc/nginx/nginx_configure/nginx"
  nginx binary file: "/usr/etc/nginx/nginx_configure/nginx/sbin/nginx"
  nginx modules path: "/usr/etc/nginx/nginx_configure/nginx/modules"
  nginx configuration prefix: "/usr/etc/nginx/nginx_configure"
  nginx configuration file: "/usr/etc/nginx/nginx_configure/nginx.conf"
  nginx pid file: "/usr/etc/nginx/nginx_configure/nginx.pid"
  nginx error log file: "/usr/etc/nginx/nginx_configure/error.log"
  nginx http access log file: "/usr/etc/nginx/nginx_configure/access.log"
  nginx http client request body temporary files: "/usr/etc/nginx/nginx_configure/client"
  nginx http proxy temporary files: "/usr/etc/nginx/nginx_configure/proxy"
  nginx http fastcgi temporary files: "/usr/etc/nginx/nginx_configure/fastcgi"
  nginx http uwsgi temporary files: "/usr/etc/nginx/nginx_configure/uwsgi"
  nginx http scgi temporary files: "scgi_temp"

則配置成功。
開始編譯:

[root@localhost nginx-1.13.3]# make && make install

執行成功:

make -f objs/Makefile
make[1]: Entering directory `/usr/etc/nginx/nginx-1.13.3'
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/un
ix -I objs \        -o objs/src/core/nginx.o \
        src/core/nginx.c
......
......
......
test -d '/usr/etc/nginx/nginx_configure/nginx/html' \
        || cp -R html '/usr/etc/nginx/nginx_configure/nginx'
test -d '/usr/etc/nginx/nginx_configure' \
        || mkdir -p '/usr/etc/nginx/nginx_configure'
make[1]: Leaving directory `/usr/etc/nginx/nginx-1.13.3'

編譯成功。

接下來需要建立目錄,在剛剛配置過程中已經確定下來的目錄

[root@localhost nginx]# mkdir -pv //usr/etc/nginx/nginx_configure/{client,proxy,fastcgi,uwsgi}

開啟nginx服務並顯示:

[root@localhost nginx-1.13.3]# /usr/etc/nginx/nginx_configure/nginx/sbin/nginx 
[root@localhost nginx-1.13.3]# ss -tnlp

顯示內容:

State       Recv-Q Send-Q                                  Local Address:Port                                    Peer Address:Port 
LISTEN      0      128                                                 *:80                                                 *:*      
users:(("nginx",20400,6),("nginx",20401,6))LISTEN      0      128                                                :::22                                                :::*      
......
......

nginx監聽80埠;
檢視程序:

[root@localhost nginx-1.13.3]# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   
......
......
root     20400  0.0  0.0  45256  1164 ?        Ss   08:26   0:00 nginx: master process /usr/etc/nginx/nginx_configure/nginx/sbin/ngin
nginx    20401  0.0  0.0  45688  1736 ?        S    08:26   0:00 nginx: worker process                          
......
......