我正在使用puma和nginx在AWS上运行rails 3.2应用程序。我在loadbalancer(ELB)上终止我的HTTPS。如何将www.mydomain.com重定向到mydomain.com?我的配置不起作用。
if ($(".correct:visible").length == $(".correct").length) {
//hide and show
}
如果我删除
user nginx;
worker_processes auto;
worker_rlimit_nofile 100000;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
use epoll;
worker_connections 1024;
multi_accept on;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
keepalive_requests 200;
reset_timedout_connection on;
types_hash_max_size 2048;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
index index.html index.htm;
upstream myapp {
# Path to Puma SOCK file
server unix:/var/www/nginx-default/myapp/tmp/sockets/puma.sock fail_timeout=0;
}
server {
listen 80;
server_name www.my-app.com;
return 301 $scheme://my-app.com$request_uri;
}
server {
listen 80;
server_name my-app.com;
root /var/www/nginx-default/myapp/public;
#charset koi8-r;
# set client body size (upload size)
client_max_body_size 100M;
location / {
proxy_pass http://myapp; # match the name of upstream directive which is defined above
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# We don't need .ht files with nginx.
location ~ /\.ht {
deny all;
}
open_file_cache max=1000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
}
}
并使用
server {
listen 80;
server_name www.my-app.com;
return 301 $scheme://my-app.com$request_uri;
}
它可以工作,但不处理www子域。
答案 0 :(得分:0)
这是一个推测性答案,因为我不使用AWS和ELB。但是,在重定向中使用html, body {
height: 100%;
width:100%;
padding: 0;
margin: 0;
box-sizing: border-box;
}
div#header {
background: red;
height: 80px;
}
div#container {
position: relative;
bottom: 0;
left: 0;
right: 0;
}
div#row_1 {
max-height: 400px;
overflow: auto;
}
div#row_2 {
min-height: 500px;
}
会导致HTTPS重定向到HTTP:
如果您不在ELB接受HTTP,则应仅使用以下方式重定向到HTTPS:
$scheme
但是,如果您在ELB上接受HTTP或HTTPS,则应该能够使用ELB插入的server {
listen 80;
server_name www.my-app.com;
return 301 https://my-app.com$request_uri;
}
标头。试试这个:
X-Forwarded-Proto