nginx 配置详解
生活随笔
收集整理的這篇文章主要介紹了
nginx 配置详解
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
請求轉發(fā)
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;} }說明:
語法說明
語法規(guī)則: location [=|~|~*|^~] /uri/ { … }= 精確匹配
^~ 以某個常規(guī)字符串開頭
~ 區(qū)分大小寫的正則匹配
~* 不區(qū)分大小寫
/ 通用匹配,任何請求都會匹配到
配置文件
# 匹配用戶 #user nobody; # 生成進程數(shù)量 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 {#設置網(wǎng)路連接序列化是否開啟accept_mutex on; #設置一個進程是否同時接受多個網(wǎng)絡連接,默認為offmulti_accept on; #事件驅動模型,select|poll|kqueue|epoll|resig|/dev/poll|eventport#use epoll; # 最多客戶端連接數(shù)量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;# 數(shù)據(jù)包累計后發(fā)送#tcp_nopush on;#連接超時時間:單位秒(s)keepalive_timeout 65;# 開啟數(shù)據(jù)打包#gzip on;server {# 端口匹配listen 8088;# 請求地址匹配server_name localhost;# 網(wǎng)頁編碼#charset koi8-r;# 指定日至文件的路徑及日志格式#access_log logs/host.access.log main;#請求的url過濾,正則匹配,~為區(qū)分大小寫,~*為不區(qū)分大小寫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# 區(qū)分大小寫匹配以.php結尾的請求#location ~ \.php$ {# 服務轉發(fā)#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;# 請求參數(shù)匹配fastcgi_params文件內(nèi)容指向的變量#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 請求轉發(fā)至 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 配置详解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 服务信息推送
- 下一篇: nested exception is