【发布时间】:2015-08-07 12:22:46
【问题描述】:
我正在尝试将促销子域附加到我已经在 https 上的网站,然后使用重定向 url 重定向到网站中的另一个页面。例如,基本上如果我的网站是https://example.com 并且有一个页面https://example.com/xyz/xyz/promo,那么当我输入https://promo.example.com 到这个页面时我想要一个浏览器重定向。我已经设置了所有相关的 AWS 路由 53 设置。
我的 nginx 服务器块有这个
server {
listen 80 default_server;
listen [::]:80 default_server;
return 301 https://example.com$request_uri;
}
server {
server_name www.example.com;
return 301 https://example.com$request_uri;
}
server {
server_name example.com;
return 301 https://example.com$request_uri;
}
server {
server_name promo.example.com;
return 301 https://example.com/xyz/xyz/promo;
}
ssl_certificate /..path/..;
ssl_certificate_key //..path/..;
ssl_dhparam /..path/...;
ssl_trusted_certificate /..path/..;
add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains; preload';
ssl_prefer_server_ciphers on;
ssl_ciphers .......; //hidden
ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_buffer_size 1400;
spdy_headers_comp 0;
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=86400;
resolver_timeout 10;
server {
listen 443 ssl spdy;
server_name example.com;
include /etc/nginx/helper.conf;
root /var/www/example/ ;
index index.php index.html;
charset utf-8;
location / {
add_header "Access-Control-Allow-Origin" "*";
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
当前行为:
当我直接输入promo.example.com 没有 https时,它会正确重定向。但如果我输入https://promo.example.com,它只会显示example.com,网址为https://promo.example.com
预期行为:
如果我输入https://promo.example.com,它应该重定向到https://example.com/xyz/xyz/promo
我不能把https://promo.example.com然后用服务器块重定向,因为nginx会抛出一个错误。
如何将https://promo.example.com 重定向到https://example.com/xyz/xyz/promo
【问题讨论】:
-
我相信 https 使用 443 端口,所以你应该为此列出端口 443
-
尝试添加这个:
listen 443 default_server ssl; -
其实我已经在我的服务器声明块里听了
443 ssl spdy,他们基本上不做同样的事情吗? -
我在上面的配置中没有看到它,所以我才这么说,serverfault.com/questions/10854/…,我认为 spdy 不应该在那里
-
如果您转到该页面 promo.example.com,http://(端口 80)会自动添加到前面。您只需将 listen 80 添加到最新的服务器块。