1. 編譯安裝nginx
1.1 安裝PCRE
(Perl Compatible Regular Expressions),中文perl兼容正則表達式.
bash -4.3 ~ # yum -y install pcre pcre-devel bash -4.3 ~ # rpm -qa | grep pcre* pcre-7.8-7.el6.x86_64 pcre-devel-7.8-7.el6.x86_64 |
1.2 安裝openssl
bash -4.3 ~ # yum -y install openssl-devel |
1.3 安裝Nginx
bash -4.3 ~ # cd /usr/local/src bash -4.3 src # tar xf nginx-1.10.1.tar.gz bash -4.3 src # cd nginx-1.10.1 bash -4.3 nginx-1.10.1 # useradd -M -s /sbin/nologin nginx bash -4.3 nginx-1.10.1 # ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module ### --user、--group: 用戶和組 ### --with-http_ssl_module: 加載ssl ### --with-http_stub_status_module: nginx監控 bash -4.3 nginx-1.10.1 # echo $? 0 bash -4.3 nginx-1.10.1 # make bash -4.3 nginx-1.10.1 # make install bash -4.3 nginx-1.10.1 # echo $? 0 bash -4.3 nginx-1.10.1 # /usr/local/nginx/sbin/nginx -V #查看Nginx配置參數 nginx version: nginx /1 .10.1 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) built with OpenSSL 1.0.1e-fips 11 Feb 2013 TLS SNI support enabled configure arguments: --prefix= /usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module |
1.4 Nginx目錄介紹
bash -4.3 nginx-1.10.1 # cd /usr/local/nginx bash -4.3 nginx # ll |awk 'NR>3 {print $NF}' conf #配置文件目錄 html #默認網站目錄 logs #日誌目錄 sbin #Nginx啓動命令 bash -4.3 nginx # /usr/local/nginx/sbin/nginx #啓動Nginx bash -4.3 nginx # lsof -i:80 #查看80端口 COMMAND PID USER FD TYPE DEVICE SIZE /OFF NODE NAME nginx 7669 root 6u IPv4 25184 0t0 TCP *:http (LISTEN) nginx 7670 nginx 6u IPv4 25184 0t0 TCP *:http (LISTEN) ### 瀏覽器訪問服務器ip |
1.5 更改默認主頁(index.html)信息
bash -4.3 nginx # cd html ### 瀏覽器訪問服務器ip |
1.6 企業場景常用的Nginx http功能模塊
ngx_http_core_module: 包括一些核心的http參數配置,對應Nginx的配置爲http區塊部分. ngx_http_access_module: 訪問控制模塊,用來控制網站用戶對Nginx的訪問. ngx_http_gzip_module: 壓縮模塊, 對Nginx返回的數據壓縮,屬於性能優化模塊. ngx_http_fastcgi_module: fastcgi模塊和動態應用相關的模塊.如php. ngx_http_proxy_module: proxy代理模塊. ngx_http_upstream_module: 負載均衡模塊 ngx_http_rewrite_module: URL地址重寫模塊 ngx_http_limit_conn_module: 限制用戶併發連接數及請求數模塊 ngx_http_limit_req_module: 限制Nginx request processing rate根據定義的key ngx_http_log_module 訪問日誌模塊,以指定的格式記錄Nginx客戶訪問日誌等信息 ngx_http_auth_basic_module: Web認證模塊,設置Web用戶通過賬號密碼訪問Nginx ngx_http_ssl_module: ssl模塊,用於加密的http連接.如https ngx_http_stub_status_module: 記錄Nginx基本訪問狀態信息等模塊 |