# Enable SSL for a specific directory?

**URL:** <https://www.ruby-forum.com/t/enable-ssl-for-a-specific-directory/214045>\
**Category:** NGINX\
**Created:** [November 19, 2011, 7:47pm UTC](https://www.ruby-forum.com/t/enable-ssl-for-a-specific-directory/214045 "2011-11-19T19:47:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [November 19, 2011, 7:47pm UTC](https://www.ruby-forum.com/t/enable-ssl-for-a-specific-directory/214045/1 "2011-11-19T19:47:44Z")

</div>

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](http://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](http://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;  
}

…  
}

Right now, I get a slashed https into browser, with the message:  
Your connection to [www.domain.com](http://www.domain.com) is encrypted with 256-bit encryption.  
However, this page includes other resources which are not secure. These  
resources can be viewed by others while in transit and can be modified  
by an attacker to change the behavior of the page.

The /protected directory is a “virtual” one that does not exist in  
reality. It is created by /index.php with some SEO technique.  
In real life, the URL format is: index.php?protected

Thanks for your help.

Posted at Nginx Forum:

> **[Enable SSL for a specific directory?](https://forum.nginx.org/read.php?2,218610,218610#msg-218610)**
>
> 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;

---

<div class="post-metadata">

**Author:** ![teck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b2d939/32.png) [@teck](https://www.ruby-forum.com/u/teck)\
**Post date:** [November 19, 2011, 10:01pm UTC](https://www.ruby-forum.com/t/enable-ssl-for-a-specific-directory/214045/2 "2011-11-19T22:01:48Z")

</div>

Hello!

On Sat, Nov 19, 2011 at 01:46:54PM -0500, TECK wrote:

[…]

> Right now, I get a slashed https into browser, with the message:  
> Your connection to [www.domain.com](http://www.domain.com) is encrypted with 256-bit encryption.  
> However, this page includes other resources which are not secure. These  
> resources can be viewed by others while in transit and can be modified  
> by an attacker to change the behavior of the page.

This is because reply from the protected page includes links to  
unprotected resources (most likely some javascript files). You  
have to load other resources from https as well.

Maxim D.

---

<div class="post-metadata">

**Author:** ![teck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b2d939/32.png) [@teck](https://www.ruby-forum.com/u/teck)\
**Post date:** [November 19, 2011, 11:34pm UTC](https://www.ruby-forum.com/t/enable-ssl-for-a-specific-directory/214045/3 "2011-11-19T23:34:56Z")

</div>

On 19 Nov 2011 18h46 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> location / {
> 
> 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

---

<div class="post-metadata">

**Author:** ![teck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b2d939/32.png) [@teck](https://www.ruby-forum.com/u/teck)\
**Post date:** [November 21, 2011, 2:15pm UTC](https://www.ruby-forum.com/t/enable-ssl-for-a-specific-directory/214045/4 "2011-11-21T14:15:17Z")

</div>

Actually, in my case the fix was to add:  
fastcgi\_param HTTPS on;

Posted at Nginx Forum:

> **[Re: Enable SSL for a specific directory?](https://forum.nginx.org/read.php?2,218610,218706#msg-218706)**
>
> 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;
