server { listen 80; server_name _; location /test/ { proxy_pass http://example.com/page.php; } }
目前,当我使用这个Nginx反向代理时,当我从test.com/test/访问时,它服务于我https://example.com/page.php但url保持不变。 当我调用$_SERVER['http_host'] ,它会返回example.com的主机名,而不是我发出请求的主机名(域中的url)。
我试过使用: proxy_set_header Host $host; 但是,这导致我运行后,404页面。
简而言之,
我想访问test.com/test并获得http://example.com/page.php, but have the when I call在PHP when I call $ _SERVER` when I call of test.com/test but have the主机名
编辑:
events { worker_connections 1024; } http { sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; server { listen 80; server_name _; location / { proxy_set_header Host $host; #works without this proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_intercept_errors on; proxy_pass http://example.com; } } }