Welcome! Log In Create A New Profile

Advanced

Re: https on a specific directory only?

Mikhail Mazursky
December 06, 2010 03:06AM
2010/12/6 TECK <nginx-forum@nginx.us>:
> Hi all,
>
> I recently purchased a SSL certificate and I would like to use it only
> on a specific location:
>
> [code]
> server {
>        listen                          10.30.1.50:80 default_server backlog=1024 rcvbuf=32k
> sndbuf=8k;
>        listen                          10.30.1.50:443 ssl;
>        server_name                     www.domain.com;
>        ssl_certificate                 domain.com.crt;
>        ssl_certificate_key             domain.com.key;
> ...
>        location / {
>                try_files               $uri $uri/ /index.php?$uri&$args;
>        }
>
>        location /dir/ {
>                auth_basic              "Restricted Access";
>                auth_basic_user_file    htpasswd;
>                rewrite         ^       https://www.domain.com/dir$request_uri? permanent;
>        }
> ...
> }
> [/code]
>
> In other words, if you access the scheme with a http value, it redirects
> you to the https scheme.
> I really don't want to use any IF's as conditionals.
> Right now, the rewrite creates a redirect loop. How can I fix that?

You can create separate servers for HTTPS and HTTP or use a rewrite
like this (not tested this config):

location /dir/ {
auth_basic "Restricted Access";
auth_basic_user_file htpasswd;
if ($server_port = 80) {
rewrite ^
https://www.domain.com/dir$request_uri? permanent;
}
}

Also, it seems that you should remove extra '/dir' from rewrite rule
and write it like this:
rewrite ^ https://www.domain.com$request_uri? permanent;

Hope it helps.

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

https on a specific directory only?

TECK December 06, 2010 02:48AM

Re: https on a specific directory only?

Mikhail Mazursky December 06, 2010 03:06AM

Re: https on a specific directory only?

François Battail December 06, 2010 03:08AM

Re: https on a specific directory only?

TECK December 06, 2010 03:13AM

Re: https on a specific directory only?

Igor Sysoev December 06, 2010 07:08AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 125
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready