António P. P. Almeida
November 19, 2011 05:36PM
On 19 Nov 2011 18h46 WET, nginx-forum@nginx.us wrote:

> Hi,
>
> I'm trying to enable SSL for a specific directory only. In other
> words, the / directory is not encrypted, while the /protected is.
>
> server {
> listen 192.168.1.2:80 default_server;
> server_name www.domain.com;
> root /var/www/html;
>
> location / {
> try_files $uri $uri/ index.php?q=$uri&$args;
> }
>
> location /protected/ {
> rewrite ^ https://www.domain.com$request_uri?
> permanent;
> }
>
> ...
> }
>
> server {
> listen 192.168.1.2:443 ssl;
> server_name www.domain.com;
> root /var/www/html;
>
> location / {
> rewrite ^ http://www.domain.com$request_uri?
> permanent;
> }
>
> location /protected/ {
> try_files $uri $uri/ /index.php?q=$uri&$args;
> }
>
> ...
> }

Define a vhost for SSL that has all the same locations, meaning static
resources and such. Then do on the HTTP host.

location ^~ /protected {
return 301 http://www.domain.com$request_uri;
}

On the SSL host:

location / {
return 301 http://www.domain.com$request_uri;
}

location ^~ /protected {
try_files $uri $uri/ /index.php?q=$uri&$args;
}

--- appa

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

Enable SSL for a specific directory?

TECK November 19, 2011 01:46PM

Re: Enable SSL for a specific directory?

Maxim Dounin November 19, 2011 04:02PM

Re: Enable SSL for a specific directory?

António P. P. Almeida November 19, 2011 05:36PM

Re: Enable SSL for a specific directory?

TECK November 21, 2011 08:15AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 162
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready