日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

nginx 配置详解

發布時間:2025/3/19 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nginx 配置详解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

請求轉發

server {listen 8088;#server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location / {#root html;#index index.html index.htm;proxy_pass http://www.baidu.com;} }

說明:

  • 通過瀏覽器請求 localhost:8088 地址,nginx匹配8088端口;
  • 獲取 location 下面的proxy_pass轉發地址 ,轉發請求至: http://www.baidu.com;
  • 語法說明

    語法規則: location [=|~|~*|^~] /uri/ { … }

    = 精確匹配

    ^~ 以某個常規字符串開頭

    ~ 區分大小寫的正則匹配

    ~* 不區分大小寫

    / 通用匹配,任何請求都會匹配到

    配置文件

    # 匹配用戶 #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 {#設置網路連接序列化是否開啟accept_mutex on; #設置一個進程是否同時接受多個網絡連接,默認為offmulti_accept on; #事件驅動模型,select|poll|kqueue|epoll|resig|/dev/poll|eventport#use epoll; # 最多客戶端連接數量worker_connections 1024; }http {# 文件類型支持conf/mime.types文件中的類型include 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 logs/access.log main;# 是否使用sendfile 方式傳輸文件sendfile on;# 數據包累計后發送#tcp_nopush on;#連接超時時間:單位秒(s)keepalive_timeout 65;# 開啟數據打包#gzip on;server {# 端口匹配listen 8088;# 請求地址匹配server_name localhost;# 網頁編碼#charset koi8-r;# 指定日至文件的路徑及日志格式#access_log logs/host.access.log main;#請求的url過濾,正則匹配,~為區分大小寫,~*為不區分大小寫location / {# 根目錄#root html;# 默認歡迎頁面#index index.html index.htm;# 拒絕的請求地址deny 127.0.0.1; # 允許的請求地址allow 172.18.5.54; }# 404異常跳轉頁面#error_page 404 /404.html;# redirect server error pages to the static page /50x.html# 500 502 503 504 異常跳轉頁面error_page 500 502 503 504 /50x.html;# 50x.html異常頁面根目錄location = /50x.html {root html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80# 區分大小寫匹配以.php結尾的請求#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;# 默認訪問頁面#fastcgi_index index.php;# 腳本文件請求路徑#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# 請求參數匹配fastcgi_params文件內容指向的變量#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# 將 8082 請求轉發至 proxy_pass 指向的服務server {listen 8082;#server_name localhost;location / {#root html;#index index.html;proxy_pass http://www.baidu.com;}}# 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;# }#}}

    總結

    以上是生活随笔為你收集整理的nginx 配置详解的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。