nginx 日常
俗子
·
2019-03-13
·
via 俗子
遇到的一些问题
- 大文件无法上传
1 2 3 4
| server{ client_max_body_size 30m; # 默认是1m ... }
|
常用配置
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
| server { listen 80; server_name hostname.com; location / { if ($request_method = GET) { rewrite ^ https://$host$request_uri? permanent; # http强制跳转 } return 405; } access_log /var/log/nginx/hostname/hostname.log main; } server { listen 443; server_name hostname.com; client_max_body_size 10m; ssl on; ssl_certificate /etc/nginx/ssl/hostname.com.crt; # ssl证书 ssl_certificate_key /etc/nginx/ssl/hostname.com.key; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $remote_addr; proxy_redirect off; # keepalive + raven.js is a disaster keepalive_timeout 0; location / { proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $host; proxy_pass http://localhost:8000; add_header Strict-Transport-Security "max-age=31536000"; } access_log /var/log/nginx/hostname/hostname_ssl.log main; error_log /var/log/nginx/hostname/hostname_ssl_error.log; }
|
正则配置
- 等号(=):表示完全匹配规则才执行操作
- 波浪号(~):表示执行正则匹配,但区分大小写
1
| location ~ /page/\d{1,3} {}
|
- 波浪号与星号(~*):表示执行正则匹配,但不 区分大小写
1
| location ~* /\.(jpg|jpeg|gif) {}
|
- 脱字符与波浪号(^~):表示普通字符匹配,前缀匹配有效,配置生效
1
| location ^~ /images/ {} # http://{hostname}/images/test
|
- @ :定义一个location,用于处理内部重定向
1 2 3 4
| location @error { proxy_pass http://error; } error_page 404 @error;
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。