Created
August 28, 2020 06:58
-
-
Save simonkuang/25e5f8be4f337d63140343b802a77b7a to your computer and use it in GitHub Desktop.
用另一个域名代理某个域名的 openresty 配置规则。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 443 ssl; | |
listen 80; | |
server_name pbs.a-domain.com abs.a-domain.com abs-0.a-domain.com; | |
server_tokens off; | |
resolver 8.8.8.8 1.1.1.1 9.9.9.9 8.8.4.4; | |
ssl_certificate ssl/a-domain.com.crt; | |
ssl_certificate_key ssl/7a-domain.com.key; | |
client_max_body_size 50M; | |
access_log /app/logs/openresty/a-domain.com.access.log; | |
error_log /app/logs/openresty/a-domain.com.error.log; | |
proxy_cache twimg; | |
proxy_temp_path /dev/shm/proxy-temp-path; | |
proxy_max_temp_file_size 1024m; | |
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504; | |
proxy_cache_lock on; | |
proxy_cache_background_update on; | |
location /~demo { | |
set_by_lua_block $newhost { | |
ngx.header.content_type = 'text/plain; charset=utf-8' | |
return string.gsub(ngx.var.host, ".a-domain.com", ".b-domain.com") | |
} | |
echo "Host is: $newhost"; | |
} | |
location / { | |
set_by_lua_block $newhost { | |
return string.gsub(ngx.var.host, ".a-domain.com", ".b-domain.com") | |
} | |
add_header X-Cache-Status $upstream_cache_status; | |
proxy_pass $scheme://$newhost$request_uri; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment