Naginx 配置詳解

#全局塊(用戶組、Pid存放地址、日誌存放、配置文件引入、進程數)
#user  nobody;  #配置用戶或者組,默認爲nobody nobody。
worker_processes  1;    #容許生成的進程數,默認爲1

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;     #指定nginx進程運行文件存放地址

#Events塊(鏈接數、多網絡鏈接、網絡鏈接序列化)
events {
    worker_connections  1024;   #鏈接數
}

#Http塊(server、配置代理、緩存、日誌定義)
http {
    include       mime.types;   #文件擴展名與文件類型映射表(MIME映射表)
    default_type  application/octet-stream; #默認文件類型,默認爲text/plain  
    #Content-Type: .*( 二進制流,不知道下載文件類型)---> application/octet-stream    例子說明 1.
    #Content-Type: .txt ---> text/plain 	例子說明 1.

    #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        on; #容許sendfile方式傳輸文件,默認爲off,能夠在http塊,server塊,location塊。
    #tcp_nopush     on; #此選項容許或禁止使用socke的TCP_CORK的選項,此選項僅在使用sendfile的時候使用

    #keepalive_timeout  0;  
    keepalive_timeout  65;  #鏈接超時時間,默認爲75s,能夠在http,server,location塊。

    #gzip  on;  #gzip壓縮

    server {
        listen       80;    #服務監聽端口
        server_name  localhost;     #監聽地址

        #charset koi8-r;    
        #charset utf-8,gbk;     #字符串設置爲utf8

        #access_log  logs/host.access.log  main;    #訪問日誌

        location / {    #配置請求的路由,以及各類頁面的處理狀況
            root   html;    #根目錄
            index  index.html index.htm;    #設置默認頁
        }

        #error_page  404              /404.html;    #404頁面

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;    #500/502/503/504頁面
        location = /50x.html {  #屬於50X頁面則訪問括號內頁面
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {    #匹配到.php結尾的文件
        #    proxy_pass   http://127.0.0.1;     #請求轉向127.0.0.1 定義的服務器列表
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;   #跳轉到靜態HTML頁面
        #    fastcgi_pass   127.0.0.1:9000;     # 表示nginx經過fastcgi_pass將用戶請求的資源
        #發給127.0.0.1:9000進行解析,這裏的nginx和php腳本解析服務器是在同一臺機器上,
        #因此127.0.0.1:9000表示的就是本地的php腳本解析服務器。
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name; #例子說明:3
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;     #禁止一個ip或者ip段訪問
        #    allow   all;     #容許一個ip或者ip段訪問
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;     #crt 文件的名稱
    #    ssl_certificate_key  cert.key;     #key 文件的名稱

    #    ssl_session_cache    shared:SSL:1m;    #ssl緩存大小,詳細說明 4.  
    #    ssl_session_timeout  5m;   #客戶端能夠重用會話緩存中ssl參數的過時時間,
    #內網系統默認5分鐘過短了,能夠設成30m即30分鐘甚至4h。

    #    ssl_ciphers  HIGH:!aNULL:!MD5;     #加密方式  詳細說明 5.
    #    ssl_prefer_server_ciphers  on;     #設置協商加密算法時,優先使用咱們服務端的加密套件,
    #而不是客戶端瀏覽器的加密套件

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

例子說明:php

  1. [root]
    語法:root path
    默認值:root html
    配置段:http、server、location、if

例如:
location ^~ /t/ {
root /www/root/html/;
}
若是一個請求的URI是/t/a.html時,web服務器將會返回服務器上的/www/root/html/t/a.html的文件。html

  1. nginx的location配置詳解
    https://www.cnblogs.com/sign-ptk/p/6723048.htmlnginx

  2. fastcgi_param 參數說明
    http://www.javashuo.com/article/p-hcpvvjtk-gh.htmlweb

  3. nginx ssl配置
    http://www.javashuo.com/article/p-qdiujhfq-ma.html算法

  4. 加密方式說明
    http://www.javashuo.com/article/p-pqdfumdy-cx.htmlsegmentfault