问题原文
原帖链接 · Alyas · CC BY-SA 4.0
I am trying to setup a reverse proxy in nginx to serve static contents. I am having issue in correctly setting up; below is my nginx config:
server {
listen 80;
server_name mysub.domain.com;
access_log off;
resolver 8.8.8.8 valid=5s;
set $backend "www.originaldomain.com";
location / {
proxy_cache my_cache;
proxy_pass https://$backend;
}
}
If I try a resource of originaldomain over mysub.domain.com .. it wouldn't work.. and if I see error log, it seems the nginx is requesting the resource to originaldomain's IP like below;
2018/06/09 17:47:13 [crit] 9825#0: *111 mkdir() "/store/cache/1" failed (13: Permission denied) while reading upstream, client: 112.123.121.11, server: mysub.domain.com, request: "GET /path/to/image.png HTTP/1.1", upstream: "https://101.181.11.120:443/path/to/image.png", host: "mysub.domain.com"
and when looking up image.png over IP, it cannot be found, to download resource correctly it needs to be looked up through domain name instead of its IP.
Any ideas?
Thanks in advance.
已采纳解答
原帖链接 · wurtel · CC BY-SA 4.0
nginx can only connect to IP addresses, that's how TCP/IP works.
In the location / stanza you need to add a line
proxy_set_header Host $backend;
to pass that header line to the backend.
I'd also investigate that mkdir() "/store/cache/1" failed (13: Permission denied) error. Either configure another location for the cache files or create /store/cache with suitable permissions for the ID nginx is running as.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
