Nginx教程2-配置文件

1.主要配置文件及介紹

Ⅰ.nginx的安裝目錄

Snipaste_2019-10-26_15-36-13.png

Ⅱ.nginx.conf總配置文件解讀: vim nginx.conf 打開文件

# 運行用戶,默認是nginx,可以不進行設(shè)置     
user  nginx;
#Nginx進程,一般設(shè)置和cpu核數(shù)一樣
worker_processes  1;

#錯誤日志存放位置
error_log  /var/log/nginx/error.log warn;
#進程pid存放位置
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;#單個后臺進程的最大并發(fā)數(shù)
}


http {
    include       /etc/nginx/mime.types;#文件擴展名和類型映射表
    default_type  application/octet-stream;#默認的文件類型
    #設(shè)置日志模式
    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  /var/log/nginx/access.log  main;#nginx訪問日志的存放位置

    sendfile        off;#是否開啟高效傳輸模式 on開啟 off關(guān)閉
    #tcp_nopush     on;#減少網(wǎng)絡(luò)報文段的數(shù)量

    keepalive_timeout  65; #保持連接的時間,也叫超時時間

    #gzip  on;#開啟gzip壓縮模式

    include /etc/nginx/conf.d/*.conf;#包含的子配置項的位置和文件
}

2.子配置文件及介紹

Ⅰ.default.conf子配置文件解讀

如果在騰訊云centos7上直接安裝nginx,會發(fā)現(xiàn)沒有該配置文件,請回到教程1,重裝系統(tǒng)后再自行配置yum源下載,單是卸載還會有nginx殘留配置

Snipaste_2019-10-27_15-07-43.png
server {
    listen       80;   #配置監(jiān)聽端口
    server_name  localhost;  //配置域名
    #charset koi8-r;     
    #access_log  /var/log/nginx/host.access.log  main;
    location / {
        root   /usr/share/nginx/html;     #服務(wù)默認啟動目錄
        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;   #錯誤狀態(tài)碼的顯示頁面,配置后需要重啟
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    # proxy the 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
    #
    #location ~ \.php$ {
    #    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;
    #}
}

Ⅱ.網(wǎng)站根目錄

Snipaste_2019-10-27_10-35-13.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容