1. 程式人生 > >windows及centOS7下的Linux下Nginx作為靜態檔案伺服器安裝及配置

windows及centOS7下的Linux下Nginx作為靜態檔案伺服器安裝及配置

windows系統

1.下載並安裝nginx,http://nginx.org/en/download.html

2.解壓,並修改conf目錄下nginx.conf配置檔案

http{#設定mime型別,型別由mime.type檔案定義include    mime.types;default_type  application/octet-stream;#設定日誌格式log_format  main'$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"'
;access_log  logs/access.log  main;#sendfile 指令指定 nginx 是否呼叫 sendfile 函式(zero copy 方式)來輸出檔案,#對於普通應用,必須設為 on,#如果用來進行下載等應用磁碟IO重負載應用,可設定為 off,#以平衡磁碟與網路I/O處理速度,降低系統的uptime.sendfile     on;#tcp_nopush     on;#連線超時時間#keepalive_timeout  0;keepalive_timeout65;tcp_nodelay     on;#開啟gzip壓縮gzip  on;gzip_disable"MSIE [1-6]."
;#設定請求緩衝client_header_buffer_size128k;large_client_header_buffers4128k;#設定虛擬主機配置server{#偵聽80埠listen80;#定義使用 www.nginx.cn訪問server_name  www.nginx.cn;#定義伺服器的預設網站根目錄位置root html;#設定本虛擬主機的訪問日誌access_log  logs/nginx.access.log  main;#預設請求location/{#定義首頁索引檔案的名稱index index.php index.html index.htm;}# 定義錯誤提示頁面error
_page500502503504/50x.html;location=/50x.html{}#靜態檔案,nginx自己處理location~^/(images|javascript|js|css|flash|media|static)/{#過期30天,靜態檔案不怎麼更新,過期可以設大一點,#如果頻繁更新,則可以設定得小一點。expires30d;}#PHP 指令碼請求全部轉發到 FastCGI處理. 使用FastCGI預設配置.location~.php${fastcgi_pass127.0.0.1:9000;fastcgi_index index.php;fastcgi_param  SCRIPT_FILENAME$document_root$fastcgi_script_name;include fastcgi_params;}#禁止訪問 .htxxx 檔案location~/.ht{deny all;}}}

其實看了那麼多,只是想讓大家多瞭解點nginx知識,

下面介紹簡單實用的操作方法:

直接在


寫入你存放資源的路徑,

在瀏覽器中直接輸入即將實現。


LINUX系統

1.安裝依賴庫

          yum install gcc-c++
          yum install pcre pcre-devel
          yum install zlib zlib-devel

          yum install openssl openssl-devel

2.檢查是否已安裝

  find -name nginx

3.安裝Nginx
              wget http://nginx.org/download/nginx-1.7.4.tar.gz     //下載壓縮檔案
          tar -zxvf nginx-1.7.4.tar.gz     //解壓檔案
          cd  nginx-1.7.4    //進入解壓檔案
          ./configure       
          make

          make install       //安裝Nginx

4.啟動Nginx

      v1、啟動:
                  /usr/local/nginx/sbin/nginx (修改檔案要修改/usr/local/nginx/conf/nginx.conf
          v2、其他命令:
                  /usr/local/nginx/sbin/nginx -s [引數]
                  引數可以是下列之一:
                  stop — 快速停止
                  quit — 優雅停止
                  reload — 重新載入配置檔案

                  reopen — 重新開啟日誌檔案

5.設定防火牆狀態

     檢視防火牆狀態

       firewall-cmd    --state

     關閉防火牆 

       systemctl  stop   firewalld.service

     開啟防火牆

      systemctl  start   firewalld.service

6.測試,直接在windows下輸入ip即可,conf下的nginx.conf配置和windows下的配置一樣。

nginx詳細介紹請參考:http://blog.csdn.net/zhaogangyyxf/article/details/79424392