91aaa在线国内观看,亚洲AV午夜福利精品一区二区,久久偷拍人视频,久久播这里有免费视播

<strong id="fvuar"></strong>

  • <sub id="fvuar"><dl id="fvuar"><em id="fvuar"></em></dl></sub>

    1. 千鋒教育-做有情懷、有良心、有品質(zhì)的職業(yè)教育機構(gòu)

      手機站
      千鋒教育

      千鋒學(xué)習(xí)站 | 隨時隨地免費學(xué)

      千鋒教育

      掃一掃進入千鋒手機站

      領(lǐng)取全套視頻
      千鋒教育

      關(guān)注千鋒學(xué)習(xí)站小程序
      隨時隨地免費學(xué)習(xí)課程

      當(dāng)前位置:首頁  >  技術(shù)干貨  > Nginx默認(rèn)配置詳解

      Nginx默認(rèn)配置詳解

      來源:千鋒教育
      發(fā)布人:xqq
      時間: 2023-11-21 15:53:29 1700553209

      一、nginx默認(rèn)配置文件

      Nginx 安裝后默認(rèn)會提供一個全局的配置文件 nginx.conf。配置文件可以通過命令行指定,也可以由運行 ./nginx 命令的用戶名所指定,除此之外,Nginx 可以使用附加的配置文件(.conf)。

      nginx.conf 配置文件位于 /etc/nginx 或 /usr/local/nginx/conf 目錄中,不同的 Linux 發(fā)行版安裝路徑可能有所不同。通過配置文件的方式,我們可以對 Nginx 進行全面的配置,以滿足不同場景的需求。

      user  nginx;
      worker_processes  auto;
      error_log  /var/log/nginx/error.log warn;
      pid        /var/run/nginx.pid;
      
      events {
          worker_connections  1024;
      }
      
      http {
          include       /etc/nginx/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  /var/log/nginx/access.log  main;
      
          sendfile        on;
          tcp_nopush     on;
      
          keepalive_timeout  65;
      
          gzip  on;
          include /etc/nginx/conf.d/*.conf;
      }
      

      二、nginx默認(rèn)配置報錯

      當(dāng)我們在編寫 Nginx 配置文件時,如果存在字符錯誤,語法錯誤或者引用了不存在目錄或文件的路徑時,會導(dǎo)致 Nginx 啟動失敗。

      在配置文件或者啟動命令出現(xiàn)問題時,可以通過以下方式獲取錯誤日志,以便檢查錯誤:

      #檢查語法錯誤
      nginx -t
      
      #啟動 nginx
      nginx
      
      #查看啟動是否成功
      ps -ef | grep nginx
      
      #獲取錯誤日志文件路徑
      tail -f /var/log/nginx/error.log
      

      三、nginx配置user值

      用戶指令,用于指定 Nginx 進程的運行用戶。

      例如,我們可以通過以下方式讓 Nginx 進程以用戶名“www”啟動:

      user www;
      

      四、nginx默認(rèn)配置文件路徑

      在 Linux 系統(tǒng)中,Nginx 的默認(rèn)配置文件存放在 /etc/nginx/nginx.conf。

      這里有幾種方法可以查找配置文件,如:

      使用 find 命令查找:find / -name nginx.conf 使用 which 命令查找可執(zhí)行文件路徑:which nginx 查看 Nginx 的啟動配置:cat /lib/systemd/system/nginx.service

      五、nginx配置server

      在 Nginx 配置文件中,我們需要為每個域名設(shè)置一個相應(yīng)的 server 塊配置。

      例如,我們可以使用以下代碼將 Nginx 配置為監(jiān)聽 80 端口,并處理 example.com 的請求:

      server {
          listen 80;
          server_name  example.com;
          root /home/example.com;
          index index.php index.html index.htm;
      }
      

      六、nginx默認(rèn)配置路徑

      Nginx 默認(rèn)情況下會在 /etc/nginx 中尋找配置文件,如果有指定 -c 參數(shù),將優(yōu)先使用指定的配置文件。

      七、nginx默認(rèn)配置文件設(shè)置

      Nginx 配置文件包含多個配置塊,每個塊通過花括號進行封閉。

      例如,在 http 配置塊中添加 server 塊:

      http {
          server {
              listen       80;
              server_name  localhost;
              location / {
                  root   /usr/share/nginx/html;
                  index  index.html index.htm;
              }
          }
      }
      

      八、nginx 配置詳解

      Nginx 配置文件分為以下幾個部分:

      啟動配置:

              user username;
              worker_processes num;
              error_log path [level];
              pid path;
        

      events 配置:

              events {
                  worker_connections num;
                  multi_accept on|off;
                  use epoll|kqueue|rt|/dev/poll|select;
                  accept_mutex on|off;
                  accept_mutex_delay time;
              }
        

      http 配置:

              http {
                  include mime.types;
                  default_type application/octet-stream;
                  access_log path [format [buffer=size]];
                  sendfile on|off;
                  tcp_nopush on|off;
                  tcp_nodelay on|off;
              }
        

      九、nginx負載均衡配置詳解

      Nginx 負載均衡配置指的是通過 Nginx 配置,將請求分發(fā)到多個后端服務(wù)器。常見的負載均衡配置方式有:

      輪詢

          upstream backend {
              server dfault_server_ip:port;
              server second_server_ip:port;
              server thrid_server_ip:port;
          }
      
          server {
              listen 80;
      
              location / {
                  proxy_pass http://backend;
              }
          } 
        

      權(quán)重

          upstream backend {
              server dfault_server_ip:port weight=5;
              server second_server_ip:port weight=3;
              server thrid_server_ip:port weight=2;
          }
      
          server {
              listen 80;
      
              location / {
                  proxy_pass http://backend;
              }
          } 
        

      IP 哈希

          upstream backend {
              ip_hash;
              server dfault_server_ip:port;
              server second_server_ip:port;
              server thrid_server_ip:port;
          }
      
          server {
              listen 80;
      
              location / {
                  proxy_pass http://backend;
              }
          } 
        

      tags: map迭代器
      聲明:本站稿件版權(quán)均屬千鋒教育所有,未經(jīng)許可不得擅自轉(zhuǎn)載。
      10年以上業(yè)內(nèi)強師集結(jié),手把手帶你蛻變精英
      請您保持通訊暢通,專屬學(xué)習(xí)老師24小時內(nèi)將與您1V1溝通
      免費領(lǐng)取
      今日已有369人領(lǐng)取成功
      劉同學(xué) 138****2860 剛剛成功領(lǐng)取
      王同學(xué) 131****2015 剛剛成功領(lǐng)取
      張同學(xué) 133****4652 剛剛成功領(lǐng)取
      李同學(xué) 135****8607 剛剛成功領(lǐng)取
      楊同學(xué) 132****5667 剛剛成功領(lǐng)取
      岳同學(xué) 134****6652 剛剛成功領(lǐng)取
      梁同學(xué) 157****2950 剛剛成功領(lǐng)取
      劉同學(xué) 189****1015 剛剛成功領(lǐng)取
      張同學(xué) 155****4678 剛剛成功領(lǐng)取
      鄒同學(xué) 139****2907 剛剛成功領(lǐng)取
      董同學(xué) 138****2867 剛剛成功領(lǐng)取
      周同學(xué) 136****3602 剛剛成功領(lǐng)取
      相關(guān)推薦HOT