<p dir="ltr"><br>
how about binding it to another port like 8080. so elb will receive request as https port 443 and send it to ec2 instance via http port 8080. will that help?</p>
<p dir="ltr">regards,<br>
nhadie<br></p>
<div class="gmail_quote">On 2 Jun 2014 01:48, "allang" <<a href="mailto:nginx-forum@nginx.us">nginx-forum@nginx.us</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On AWS, I'm trying to migrate a PHP Symfony app running on nginx. I want to<br>
be able to test the app by directly talking to the EC2 server and via an<br>
Elastic Load Balancer (ELB -the public route in).<br>
<br>
I've setup the ELB to decrypt all the SSL traffic and pass this on to my EC2<br>
server via port 80, as well as pass port 80 directly onto my EC2 server via<br>
port 80.<br>
<br>
Initially this caused infinite redirects in my app but I researched and then<br>
fixed this by adding<br>
<br>
fastcgi_param HTTPS $https;<br>
with some custom logic that looks at $http_x_forwarded_proto to figure out<br>
when its actually via SSL.<br>
<br>
There remains one issue I can't solve. When a user logs into the Symfony<br>
app, if they come via the ELB, the form POST eventually returns a redirect<br>
back to <a href="https://elb.mysite.com:80/dashboard" target="_blank">https://elb.mysite.com:80/dashboard</a> instead of<br>
<a href="https://elb.mysite.com/dashboard" target="_blank">https://elb.mysite.com/dashboard</a> which gives the user an error of "SSL<br>
connection error".<br>
<br>
I've tried setting<br>
<br>
fastcgi_param SERVER_PORT $fastcgi_port;<br>
to force it away from 80 and I've also added the<br>
<br>
port_in_redirect off<br>
directive but both make no difference.<br>
<br>
The only way I've found to fix this is to alter the ELB 443 listener to pass<br>
traffic via https. The EC2 server has a self certified SSL certificate<br>
configured. But this means the EC2 server is wasting capacity performing<br>
this unnecessary 2nd decryption.<br>
<br>
Any help very much appreciated. Maybe there is a separate way within nginx<br>
of telling POST requests to not apply port numbers?<br>
<br>
Nginx vhost config:<br>
server {<br>
port_in_redirect off;<br>
<br>
listen 80;<br>
listen 443 ssl;<br>
<br>
ssl_certificate /etc/nginx/ssl/<a href="http://mysite.com/self-ssl.crt" target="_blank">mysite.com/self-ssl.crt</a>;<br>
ssl_certificate_key /etc/nginx/ssl/<a href="http://mysite.com/self-ssl.key" target="_blank">mysite.com/self-ssl.key</a>;<br>
<br>
# Determine if HTTPS being used either locally or via ELB<br>
set $fastcgi_https off;<br>
set $fastcgi_port 80;<br>
if ( $http_x_forwarded_proto = 'https' ) {<br>
# ELB is using https<br>
set $fastcgi_https on;<br>
# set $fastcgi_port 443;<br>
}<br>
if ( $https = 'on' ) {<br>
# Local connection is using https<br>
set $fastcgi_https on;<br>
# set $fastcgi_port 443;<br>
}<br>
<br>
server_name *.<a href="http://mysite.com" target="_blank">mysite.com</a><br>
<a href="http://my-mysite-com-1234.eu-west-1.elb.amazonaws.com" target="_blank">my-mysite-com-1234.eu-west-1.elb.amazonaws.com</a>;<br>
<br>
access_log /var/log/nginx/access.log;<br>
error_log /var/log/nginx/error.log error;<br>
<br>
rewrite ^/app\.php/?(.*)$ /$1 permanent;<br>
<br>
location / {<br>
port_in_redirect off;<br>
root /var/www/vhosts/<a href="http://mysite.com/web" target="_blank">mysite.com/web</a>;<br>
index app.php index.php index.html index.html;<br>
try_files $uri @rewriteapp;<br>
}<br>
<br>
location ~* \.(jpg|jpeg|gif|png)$ {<br>
root /var/www/vhosts/<a href="http://mysite.com/web" target="_blank">mysite.com/web</a>;<br>
access_log off;<br>
log_not_found off;<br>
expires 30d;<br>
}<br>
<br>
location ~* \.(css|js)$ {<br>
root /var/www/vhosts/<a href="http://mysite.com/web" target="_blank">mysite.com/web</a>;<br>
access_log off;<br>
log_not_found off;<br>
expires 2h;<br>
}<br>
<br>
location @rewriteapp {<br>
rewrite ^(.*)$ /app.php/$1 last;<br>
}<br>
<br>
location ~ ^/(app|app_dev|config)\.php(/|$) {<br>
port_in_redirect off;<br>
fastcgi_pass <a href="http://127.0.0.1:9000" target="_blank">127.0.0.1:9000</a>;<br>
fastcgi_split_path_info ^(.+\.php)(/.*)$;<br>
fastcgi_param HTTPS $fastcgi_https;<br>
# fastcgi_param SERVER_PORT $fastcgi_port;<br>
#fastcgi_index index.php;<br>
fastcgi_param SCRIPT_FILENAME<br>
/var/www/vhosts/<a href="http://mysite.com/web$fastcgi_script_name" target="_blank">mysite.com/web$fastcgi_script_name</a>;<br>
include fastcgi_params;<br>
}<br>
}<br>
<br>
Posted at Nginx Forum: <a href="http://forum.nginx.org/read.php?2,250545,250545#msg-250545" target="_blank">http://forum.nginx.org/read.php?2,250545,250545#msg-250545</a><br>
<br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br>
</blockquote></div>