国产睡熟迷奷白丝护士系列精品,中文色字幕网站,免费h网站在线观看的,亚洲开心激情在线

      <sup id="hb9fh"></sup>
          1. 千鋒教育-做有情懷、有良心、有品質的職業(yè)教育機構

            手機站
            千鋒教育

            千鋒學習站 | 隨時隨地免費學

            千鋒教育

            掃一掃進入千鋒手機站

            領取全套視頻
            千鋒教育

            關注千鋒學習站小程序
            隨時隨地免費學習課程

            當前位置:首頁  >  技術干貨  > Nginx默認配置詳解

            Nginx默認配置詳解

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

            一、nginx默認配置文件

            Nginx 安裝后默認會提供一個全局的配置文件 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默認配置報錯

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

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

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

            三、nginx配置user值

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

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

            user www;
            

            四、nginx默認配置文件路徑

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

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

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

            五、nginx配置server

            在 Nginx 配置文件中,我們需要為每個域名設置一個相應的 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默認配置路徑

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

            七、nginx默認配置文件設置

            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ā)到多個后端服務器。常見的負載均衡配置方式有:

            輪詢

                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;
                    }
                } 
              

            權重

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