Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nginx #58

Open
magicdawn opened this issue Dec 25, 2015 · 10 comments
Open

nginx #58

magicdawn opened this issue Dec 25, 2015 · 10 comments

Comments

@magicdawn
Copy link
Owner

tips on nginx.

@magicdawn
Copy link
Owner Author

links

commands

  • 测试 syntax nginx -t
  • 重启 nginx -s reload # 即是发送一个 reload singal

location策略

# 精确匹配
# = `路径`
location = /a/b.js {
  # blabla
}

# 路径以xx开头
# `^~` `路径`
location ^~ /public {
  # blabla
}

# 正则
# `~` 正则
location ~ /(aaaa|bbbb) {
  # blabla
}

# 匹配所有
location / {
  # blabla
}

@magicdawn
Copy link
Owner Author

nginx 反代 websocket

https://www.nginx.com/blog/websocket-nginx/

@magicdawn
Copy link
Owner Author

syntax

map

map baseVar derivedVar{
  default a;
  '' b;
}

@magicdawn
Copy link
Owner Author

^~ /abc & ^~ /abc/

proxy_pass localhost:1234/

^~ /abc

访问 /abc/def , 则后面收到的是 //def

^~ /abc/

访问 /abc/def, 则后面收到的是 /def

@magicdawn
Copy link
Owner Author

@magicdawn
Copy link
Owner Author

magicdawn commented Aug 18, 2016

proxy 反代模块

proxy_pass

https://my.oschina.net/foreverich/blog/1512304

# 会将 prefix 删除
proxy_pass backend/; 

# 会保留 prefix
proxy_pass backend;

@magicdawn
Copy link
Owner Author

performance 优化

https://www.nginx.com/blog/tuning-nginx/

@magicdawn
Copy link
Owner Author

webpack index.html 不缓存配置

@magicdawn
Copy link
Owner Author

magicdawn commented Aug 24, 2017

understanding nginx blocks

https://www.digitalocean.com/community/tutorials/understanding-nginx-server-and-location-block-selection-algorithms

location 顺序

  1. exact, location =
  2. eaact prefix location ^~ /blabla
  3. regex location ~* \.html
  4. prefix location /blabla

前端 SPA 部署

  1. 使用 ^~
location ^~ /app {
  try_files $uri /app/index.html
  add_header Cache-Control max-age=86400;
}

location = /app/index.html {
  add_header Cache-Control no-cache;
}

使用 ^~ 在 block 里使用 root / alias
上面应该在 server context 里写了 root / alias

location ^~ /app {
  try_files $uri /app/index.html;
  alias /some/dir/dist/;
  add_header Cache-Control max-age='86400;
}

location = /app/index.html {
  alias /some/dir/dist/index.html;
  add_header Cache-Control no-cache;
}

使用 /prefix

location /app{
  try_files $uri /app/index.html
  add_header Cache-Control max-age=86400;
}

location \.html$ {
  add_header Cache-Control no-cache;
}

@magicdawn
Copy link
Owner Author

add_header

  • add_header 默认会在 upstream 返回 2xx / 3xx 增加 header
  • > 1.7.5 可以写 add_header name value always, 忽略 upstream 的 status code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant