前言
Nginx的反向代理功能应该是Nginx诸多功能里面最常用的一个功能了,正向代理的话可能使用的场景比较少,平时接触的也不多,本章内容仅包含这两个功能的基本使用配置,因为是本地版本的,所以不包含负载均衡相关的内容。
完整配置和注释
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| user root owner; worker_processes 4;
pid /Users/martin/nginx.pid;
events { worker_connections 256; }
http { include mime.types; default_type application/octet-stream;
keepalive_timeout 65;
gzip on;
server { listen 443 ssl; server_name app.doodl6.com; ssl on; ssl_certificate /Users/martin/Documents/ssl/doodl6.crt; ssl_certificate_key /Users/martin/Documents/ssl/doodl6.key;
charset UTF-8;
location ~* ^.+\.(xls|woff2|log|jpg|jpeg|gif|png|ico|html|cfm|cfc|afp|asp|lasso|pl|py|txt|fla|swf|zip|js|css|less)$ { proxy_pass https://127.0.0.1:80; proxy_set_header Host $http_host; proxy_set_header referer "$http_referer"; }
location = / { proxy_pass https://127.0.0.1:8080; proxy_set_header Host $http_host; }
location ~ / { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $http_host; } }
server { listen 80; server_name app.doodl6.com; charset UTF-8;
location ~* ^.+\.(xls|woff2|log|jpg|jpeg|gif|png|ico|html|cfm|cfc|afp|asp|lasso|pl|py|txt|fla|swf|zip|js|css|less|ico)$ { expires 30s; root /Users/martin/project/app/front; }
location ~ / { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $http_host; } }
server{ listen 82; resolver 8.8.8.8; resolver_timeout 10s; location / { proxy_pass http://$http_host$request_uri; proxy_set_header Host $http_host; proxy_buffers 256 4k; proxy_max_temp_file_size 0; proxy_connect_timeout 30; proxy_cache_valid 200 302 10m; proxy_cache_valid 301 1h; proxy_cache_valid any 1m; } }
server { listen 80; server_name proxy.doodl6.com; charset UTF-8;
location ~ / { proxy_pass http://127.0.0.1:82; proxy_set_header Host $http_host; } }
}
|