我的目标是在同一个域中拥有一个在Heroku(网站)上运行的Rails Web应用程序-响应根目录( www.example.com )上的请求以及在wordpress.com上托管的博客-响应/ blog路径( www.example.com/blog )上的请求。 目前,heroku在我的domain.com(网络dyno)上管理证书,而我的blog.domain.com也有wordpress颁发的证书。
nginx.conf
才能与SSL一起正常使用?由于我是在Heroku上托管的,因此无法为我的dyno提供IP地址,因此我必须重定向到我的域(已经映射到heroku dns)。对于博客部分,我wordpress.com也没有提供IP地址,因此我必须使用已经映射的子域(博客),并且工作正常。
# nginx.conf
events {}
http {
server {
listen $PORT;
# listen 443 ssl; # localhost debugging
# ssl_certificate localhost.crt; # localhost debugging
# ssl_certificate_key localhost.key; # localhost debugging
location / {
proxy_redirect off;
proxy_ssl_server_name on; # To avoid 502 bad gateway
proxy_set_header Host $host; # If I put this, I stop being redirected to domain.com (URL rewrite) but I face 502 bad gateway issue
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass https://example.com:443;
}
location /blog/ {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass https://blog.example.com:443;
}
}
}
我期望的是在两个网站/博客上都通过www.domain.com进行导航,而无需进行任何重定向或URL重写。我得到的是带有URL更改的重定向(302)或502错误的网关(当我尝试使用上述配置时)-如果我设置了“主机”标头。