Nginx伺服器基礎配置詳解 nginx 靜態伺服器 403 nginx做檔案伺服器 nginx配

來源:互聯網
上載者:User
Nginx配置整體認識

預設情況下,Nginx伺服器設定檔都存放在安裝目錄Conf中,主設定檔名為nginx.conf 。其內容如下:

#user  nobody;                            #全域塊worker_processes  1;#error_log  logs/error.log;#error_log  logs/error.log  notice;#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {                                   #events 塊    worker_connections  1024;}http {                                      #http塊    include       mime.types;               #http全域塊    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;    #tcp_nopush     on;#keepalive_timeout  0;    keepalive_timeout  65;    #gzip  on;    server {                                #server塊        listen       80;                    #server全域塊        server_name  localhost;        #charset koi8-r;#access_log  logs/host.access.log  main;        location / {                       #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   500502503504  /50x.html;        location = /50x.html {           #location塊            root   html;        }        # proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {             #location塊#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {           #location塊#    root           html;#    fastcgi_pass   127.0.0.1:9000;#    fastcgi_index  index.php;#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}    }    # another virtual host using mix of IP-, name-, and port-based configuration##server {                              #server塊#    listen       8000;#    listen       somename:8080;#    server_name  somename  alias  another.alias;#    location / {                     #location塊#        root   html;#        index  index.html index.htm;#    }#}# HTTPS server##server {#    listen       443 ssl;#    server_name  localhost;#    ssl_certificate      cert.pem;#    ssl_certificate_key  cert.key;#    ssl_session_cache    shared:SSL:1m;#    ssl_session_timeout  5m;#    ssl_ciphers  HIGH:!aNULL:!MD5;#    ssl_prefer_server_ciphers  on;#    location / {#        root   html;#        index  index.html index.htm;#    }#}}

從設定檔我們可以總結如下

nginix.conf配置一共有三塊組成:全域塊、events塊和http塊。在http塊中,包含多個server塊,每個server塊中又可以包含多個location塊。

設定檔各模組意義

全域塊

全域塊是預設設定檔從開始到events模組之間的一部分內容。主要設定一下影響Nginx伺服器整體啟動並執行配置指令,該指令範圍是Nginix伺服器全域。
通常包括運行Nginx伺服器使用者(組)、允許生產的worker process數、Nginix進程Pid存放路徑、日誌存放路徑和類型以及設定檔引入等。

events塊

events塊涉及的指令主要影響Nginx伺服器與使用者的網路連接。常用配置有:
是否開啟對多worker process下的網路連接進行序列化;
是否允許同時接受多個網路連接;
選擇哪種事件模型處理串連請求;
每個worker process 可以同時支援的最大串連數等。
這一部分指令對Nginix伺服器的效能影響較大,在實際配置中,應該根據實際情況,靈活調整。

http塊

http塊是Nginix伺服器配置中重要部分。代理、緩衝和記錄定義絕大部分功能和第三方模組的配置都可以放到這個模組。http全域塊中主要配置如下:
檔案引入;
MIME-TYPE定義;
日誌自訂;
是否使用sendfile傳輸檔案;
連線逾時時間;
單串連請求數上線等

server塊

server塊和“虛擬機器主機”概念有著密切聯絡。每個server塊可以相當是一台虛擬機器主機。server塊的範圍為本server塊,不會影響到其他的server塊。和http塊相同,server塊也可以包含自己的全域塊,同時還可以包含多個location塊。server全域塊主要的兩個配置如下:
虛擬機器主機的監聽配置;
虛擬機器主機的名稱或者ip配置

location塊

每個server塊可以包含多個location塊,從嚴格意思來說,location其實是server是server塊的一個指令。主要作用是,基與Nginx伺服器接受到的請求字串,對除虛擬機器主機名之外的字串進行匹配,對特定的請求進行處理。地址定向、資料緩衝和應答控制等功能都在這部分實現。

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('
  • ').text(i)); }; $numbering.fadeIn(1700); }); });

    以上就介紹了Nginx伺服器基礎配置詳解,包括了nginx,伺服器方面的內容,希望對PHP教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.