【发布时间】:2017-11-22 12:51:03
【问题描述】:
我们在 Google Cloud HTTP(S) 负载均衡器后面有 4 台带有 php 应用程序和 nginx 的服务器。 我让服务器同时监听 http 和 https 连接。 问题是 - 我不能强制使用 ssl。 这是nginx配置:
server {
listen 80;
server_name domain.com;
root /var/www/dev/public_html;
index index.php index.html index.htm;
port_in_redirect off;
location / {
return 301 https://$server_name$request_uri;
}
}
server {
listen 443;
ssl on;
ssl_certificate /etc/nginx/ssl/ssl.crt;
ssl_certificate_key /etc/nginx/ssl/ssl.key;
ssl_prefer_server_ciphers on;
root /var/www/production/public_html;
index index.php index.html index.htm;
server_name domain.com;
location ~ /help {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
proxy_redirect off;
proxy_next_upstream error;
}
location / {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
include fastcgi_params;
proxy_buffering off;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Referer "";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
}
}
那里还有几个位置,都具有相似的配置。 这个配置在没有 LB 的情况下在单个服务器上工作。并且不适用于LB。 请指教。
谢谢!
【问题讨论】:
标签: http nginx https google-cloud-platform load-balancing