Perl Dancer and HTTPS #910

Closed
mfouilleul opened this Issue Apr 9, 2013 · 12 comments

Comments

Projects
None yet
3 participants

Hi,

I setted up an Perl Dancer Website over Nginx et plackup/starman.

I'm using HTTPS but I have some trouble with URLs.

For instance, when I use :
redirect uri_for('/dashboard');
or
redirect '/dashboard';

The browser try to acceed with simple HTTP request and ommit HTTPS in front of my URL.

Do you know how can i skirt this?

Best Regards

Owner

racke commented Apr 9, 2013

On 04/09/2013 11:36 AM, mfouilleul wrote:

Hi,

I setted up an Perl Dancer Website over Nginx et plackup/starman.

I'm using HTTPS but I have some trouble with URLs.

For instance, when I use :
redirect uri_for('/dashboard');
or
redirect '/dashboard';

The browser try to acceed with simple HTTP request and ommit HTTPS in front of my URL.

Do you know how can i skirt this?

I suppose you have

behind_proxy : 1

in your configuration.

The suggested Nginx configuration in

https://metacpan.org/module/Dancer::Deployment

misses a little piece:

 proxy_set_header X-Forwarded-Proto $scheme;

Or explicitly:

proxy_set_header X-Forwarded-Proto https;

Regards
Racke

LinuXia Systems => http://www.linuxia.de/
Expert Interchange Consulting and System Administration
ICDEVGROUP => http://www.icdevgroup.org/
Interchange Development Team

Hi, thanks for your help!

In my config.yml : i've just set behind_proxy: 'true'

My nginx conf looks like this :

upstream perldancer_project_https {
server unix:/srv/www/project/tmp/project_https.sock;
}

server {
listen 443 ssl;

ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;

access_log /srv/www/project/logs/access_https.log;
error_log /srv/www/project/logs/error_https.log;

root /srv/www/project/https_html/project/public;

location / {
try_files $uri @Proxy;
access_log off;
expires max;
}

location @Proxy {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_pass http://perldancer_project_https;
}

}

And i launch my website with :
sudo -u www-data plackup -E development -s Starman -l /srv/www/project/tmp/project_https.sock -a bin/app.pl

But still the same :(

Thanks

And if i change "proxy_pass http://perldancer_project_https;" to "proxy_pass https://perldancer_project_https;" i have a 502

i found and "uggly" solution :

In my "before" hook :

$app_url = request->base;
$app_url =~s/http/https/g;

Then when i want redirect in routes, i use :

redirect $app_url . 'something';

Bad bad bad...

Owner

racke commented Apr 9, 2013

On 04/09/2013 03:19 PM, mfouilleul wrote:

i found and "uggly" solution :

In my "before" hook :

$app_url = request->base;
$app_url =~s/http/https/g;

Then when i want redirect in routes, i use :

redirect $app_url . 'something';

Bad bad bad...

Indeed. behind_proxy + proxy_set_header X-Forwarded-Proto https;
works for me.

Regards
Racke

LinuXia Systems => http://www.linuxia.de/
Expert Interchange Consulting and System Administration
ICDEVGROUP => http://www.icdevgroup.org/
Interchange Development Team

My configuration files look right for you or not?

Owner

racke commented Apr 9, 2013

On 04/09/2013 03:28 PM, mfouilleul wrote:

My configuration files look right for you or not?

Yes, the only notable difference that I see is that you run the Dancer
application on a socket, while I use a port.

Regards
Racke

LinuXia Systems => http://www.linuxia.de/
Expert Interchange Consulting and System Administration
ICDEVGROUP => http://www.icdevgroup.org/
Interchange Development Team

Ok,

But you can run Dancer on port with plackup/starman/nginx configuration?

OK i changed
proxy_pass http://perldancer_project_https;
to
proxy_pass http://127.0.0.1:5001;

And sudo -u www-data plackup -E development -s Starman -p 5001 -a bin/app.pl

But still the same

Owner

racke commented Apr 9, 2013

On 04/09/2013 03:56 PM, mfouilleul wrote:

Ok,

But you can run Dancer on port with plackup/starman/nginx configuration?

Yes.

Nginx:

       proxy_pass       http://localhost:5000;

Plackup/Starman:

DANCER_CMD=$(which plackup)

DANCER_CMDOPTS="-E $DANCER_ENVIRONMENT -s Starman --workers=$DANCER_WORKERS --pid $DANCER_PIDFILE -p $DANCER_PORT -a bin/app.pl -D"

Regards
Racke


Reply to this email directly or view it on GitHub:
#910 (comment)

LinuXia Systems => http://www.linuxia.de/
Expert Interchange Consulting and System Administration
ICDEVGROUP => http://www.icdevgroup.org/
Interchange Development Team

request->base still equal to http://blablabla

yanick added a commit that referenced this issue May 13, 2013

Contributor

yanick commented May 13, 2013

From what I can see, this looks more like a support issue than a bug with the code itself. I'll close it. If anyone involved think that there is indeed something wrong with the code, please feel free to open the issue again.

@yanick yanick closed this May 13, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment