Ruby on rails Rails应用程序在本地使用nginx,但在部署到EC2时重定向301
我有一个停靠的Rails应用程序,还有一个nginx容器,其中包含一些我已经设置好的运行时自定义配置。这个设置在我的本地机器上运行得非常好 我启动docker compose和指向应用程序网络的nginx容器,一切都像一个魔咒。我可以在localhost而不是localhost:8000上访问应用程序 但是,我目前正在AWS ECS上部署此功能,这里涉及一个带有HTTPS的负载平衡器 应用程序得到部署,两个容器都运行良好,但我点击的URL返回永久移动的301 这是我的default.confRuby on rails Rails应用程序在本地使用nginx,但在部署到EC2时重定向301,ruby-on-rails,amazon-web-services,docker,nginx,amazon-elb,Ruby On Rails,Amazon Web Services,Docker,Nginx,Amazon Elb,我有一个停靠的Rails应用程序,还有一个nginx容器,其中包含一些我已经设置好的运行时自定义配置。这个设置在我的本地机器上运行得非常好 我启动docker compose和指向应用程序网络的nginx容器,一切都像一个魔咒。我可以在localhost而不是localhost:8000上访问应用程序 但是,我目前正在AWS ECS上部署此功能,这里涉及一个带有HTTPS的负载平衡器 应用程序得到部署,两个容器都运行良好,但我点击的URL返回永久移动的301 这是我的default.conf u
upstream PLACEHOLDER_BACKEND_NAME {
server PLACEHOLDER_BACKEND_NAME:PLACEHOLDER_BACKEND_PORT;
}
server {
listen 80;
server_name www.PLACEHOLDER_VHOST;
return 301 https://$host$request_uri;
}
server {
listen 80 default deferred;
server_name PLACEHOLDER_VHOST;
root /PLACEHOLDER_BACKEND_NAME/public;
# level due to Rail's asset pipeline.
location ~ ^/assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
add_header Last-Modified "";
add_header ETag "";
}
location ~ /\. {
return 404;
access_log off;
log_not_found off;
}
try_files $uri $uri/index.html $uri.html @PLACEHOLDER_BACKEND_NAME;
location = /favicon.ico {
try_files /favicon.ico = 204;
access_log off;
log_not_found off;
}
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains;";
location @PLACEHOLDER_BACKEND_NAME {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
if ($http_x_forwarded_proto = "http") {
return 301 https://$host$request_uri;
}
proxy_pass http://PLACEHOLDER_BACKEND_NAME;
}
}
以下是我在容器启动时运行的脚本:
#!/usr/bin/env bash
set -e
PLACEHOLDER_BACKEND_NAME="my-api"
PLACEHOLDER_BACKEND_PORT="8000"
PLACEHOLDER_VHOST="$(curl http://169.254.169.254/latest/meta-data/public-hostname)"
DEFAULT_CONFIG_PATH="/etc/nginx/conf.d/default.conf"
sed -i "s/PLACEHOLDER_VHOST/${PLACEHOLDER_VHOST}/g" "${DEFAULT_CONFIG_PATH}"
sed -i "s/PLACEHOLDER_BACKEND_NAME/${PLACEHOLDER_BACKEND_NAME}/g" "${DEFAULT_CONFIG_PATH}"
sed -i "s/PLACEHOLDER_BACKEND_PORT/${PLACEHOLDER_BACKEND_PORT}/g" "${DEFAULT_CONFIG_PATH}"
# Execute the CMD from the Dockerfile and pass in all of its arguments.
exec "$@"
我甚至尝试将脚本中的占位符_VHOST设置为我的ELB公共DNS,但没有效果。这里可能有什么问题