nginx 配置文件解析

nginx配置文件的結構:
......
events
{
......
}

http
{
......
server
{
......
}

server
{
......
}
......
}


簡單的介紹一下nginx配置文件:nginx.conf

user  www;               # 定義啓動nginx的用戶
worker_processes  1;            # 指定啓動的子進程數,通常爲CPU總核數或者總核數2倍

#error_log  logs/error.log;
error_log  logs/error.log  notice;      # 指定錯誤日誌存放位置以及記錄級別,包括:debug|info|notice|warn|error|crit
#error_log  logs/error.log  info;

pid        logs/nginx.pid;           # 指定pid文件存放路徑


events {
    worker_connections  1024;             # 容許的鏈接數
    use   epoll; # 設置網絡IO模型爲epoll
}


http {
    include       mime.types;       # 設定mime類型,類型由mime.type文件定義
    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        on;               # 指定是否調用sendfile函數來輸出文件,對於普通應用必須設爲on,若是用來進行下載等應用磁盤IO重負載應用,可設置爲off,以平衡磁盤與網絡IO處理速度,下降系統uptime
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;          # 設置鏈接超時時間

# 虛擬主機配置
    server{
        listen          80;               # 監聽80端口       
        server_name     www.vhost001.com;        # 指定服務器域名
        location / {
                index index.html index.htm;           # 指定首頁索引文件的名稱
                root /usr/local/nginx/html/vhost001;   # 指定服務器的默認網站根目錄位置
                }
        }

    gzip  on;          # 設置開啓gzip壓縮傳輸

    #server {
    #    listen       80;
    #    server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

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

        # error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        # error_page   500 502 503 504  /50x.html;         # 定義錯誤頁面
        # location = /50x.html { 
        #   root   html;
        #}
        # proxyothe PHP scripts to Apache listening on 127.0.0.1:80
        #
        # location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        
# 定義php解析
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;  # 定義解析php程序使用的fastcgi接口
        #    fastcgi_index  index.php;      # 定義php程序首頁索引文件的名稱
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
    #}
    # another virtual host using mix of IP-, name-, and port-based configuration

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

    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers   on;

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

配置完成後,重啓nginx以前,須要先檢測配置是否有錯:
#  /usr/local/nginx/sbin/nginx -t                 
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful

若是沒有報錯,則能夠正常重啓nginx
service nginx reload 
或者
kill -HUP nginx主進程號
相關文章
相關標籤/搜索