# Ssl accelerator

**URL:** <https://www.ruby-forum.com/t/ssl-accelerator/166787>\
**Category:** NGINX\
**Created:** [April 29, 2009, 4:16pm UTC](https://www.ruby-forum.com/t/ssl-accelerator/166787 "2009-04-29T16:16:03Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![lovewadhwa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bc8723/32.png) [@lovewadhwa](https://www.ruby-forum.com/u/lovewadhwa)\
**Post date:** [April 29, 2009, 4:16pm UTC](https://www.ruby-forum.com/t/ssl-accelerator/166787/1 "2009-04-29T16:16:03Z")

</div>

Hi

I m using nginx to configure ssl accelerator.Have specified the  
following in my configuration file to accomplish the same:

```
upstream dev1.magazine.com{
     server dev1.magazine.com:8000;
          }

```

server {  
listen 443;  
server\_name 192.168.8.31;  
ssl on;  
ssl\_certificate server.crt;  
ssl\_certificate\_key server.key;  
location / {  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_set\_header Host $http\_host;  
proxy\_set\_header X-FORWARDED\_PROTO https;  
proxy\_redirect false;  
if (!-f $request\_filename) {  
proxy\_pass [http://dev1.magazine.com](http://dev1.magazine.com);  
}  
root html;  
index index.html index.htm;  
}

Setting the above things in my configuration file, i have my request say  
[https://192.168.8.31](https://192.168.8.31) being translated to [http://dev1.magazine.com](http://dev1.magazine.com) on  
port 8000, but the page returned is over http instead of that being  
https. Please help.

Posted at Nginx Forum:

> **[ssl accelerator](https://forum.nginx.org/read.php?2,1545,1545#msg-1545)**
>
> Hi I m using nginx to configure ssl accelerator.Have specified the following in my configuration file to accomplish the same: upstream dev1.magazine.com{ server dev1.magazine.com:8000; } server {

---

<div class="post-metadata">

**Author:** ![lovewadhwa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bc8723/32.png) [@lovewadhwa](https://www.ruby-forum.com/u/lovewadhwa)\
**Post date:** [April 30, 2009, 1:31pm UTC](https://www.ruby-forum.com/t/ssl-accelerator/166787/2 "2009-04-30T13:31:39Z")

</div>

If anybody out there can help me out.

Posted at Nginx Forum:

> **[Re: ssl accelerator](https://forum.nginx.org/read.php?2,1545,1582#msg-1582)**
>
> Hi I m using nginx to configure ssl accelerator.Have specified the following in my configuration file to accomplish the same: upstream dev1.magazine.com{ server dev1.magazine.com:8000; } server {

---

<div class="post-metadata">

**Author:** ![lovewadhwa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bc8723/32.png) [@lovewadhwa](https://www.ruby-forum.com/u/lovewadhwa)\
**Post date:** [April 30, 2009, 2:19pm UTC](https://www.ruby-forum.com/t/ssl-accelerator/166787/3 "2009-04-30T14:19:58Z")

</div>

On Wed, Apr 29, 2009 at 10:08:49AM -0400, lovewadhwa wrote:

> ```
> listen 443;
> if (!-f $request_filename) {
> proxy_pass http://dev1.magazine.com;
> }
> root html;
> index index.html index.htm;
> }
> 
> ```
> 
> Setting the above things in my configuration file, i have my request say [https://192.168.8.31](https://192.168.8.31) being translated to [http://dev1.magazine.com](http://dev1.magazine.com) on port 8000, but the page returned is over http instead of that being https. Please help.

Probably, you need to rewrite redirects:

```
   proxy_redirect http://dev1.magazine.com:8000/ /;

```

Also, it’s better to use this configuration

```
   location / {
       root html;
       index index.html index.htm;
       try_files $uri @magazine;
   }

   locaiton @magazine {
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header Host $http_host;
       proxy_set_header X-FORWARDED_PROTO https;

       proxy_pass http://dev1.magazine.com:8000;
   }

```

without “if” and “upstream [dev1.magazine.com](http://dev1.magazine.com)”.

By default

```
   proxy_pass http://dev1.magazine.com:8000;

```

also adds

```
   proxy_redirect http://dev1.magazine.com:8000/ /;

```

---

<div class="post-metadata">

**Author:** ![lovewadhwa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bc8723/32.png) [@lovewadhwa](https://www.ruby-forum.com/u/lovewadhwa)\
**Post date:** [May 1, 2009, 12:49am UTC](https://www.ruby-forum.com/t/ssl-accelerator/166787/4 "2009-05-01T00:49:21Z")

</div>

Igor,

Can you explain why it’s better to use this format?

–J

Igor S. wrote:

> Also, it’s better to use this configuration
> 
> ```
> location / {
> root html;
> index index.html index.htm;
> try_files $uri @magazine;
> }
> 
> locaiton @magazine {
> proxy_set_header X-Real-IP $remote_addr;
> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
> proxy_set_header Host $http_host;
> proxy_set_header X-FORWARDED_PROTO https;
> 
> proxy_pass http://dev1.magazine.com:8000;
> }
> 
> ```
> 
> without “if” and “upstream [dev1.magazine.com](http://dev1.magazine.com)”.
> 
> By default
> 
> ```
> proxy_pass http://dev1.magazine.com:8000;
> 
> ```
> 
> also adds
> 
> ```
> proxy_redirect http://dev1.magazine.com:8000/ /;
> 
> ```

---

<div class="post-metadata">

**Author:** ![lovewadhwa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bc8723/32.png) [@lovewadhwa](https://www.ruby-forum.com/u/lovewadhwa)\
**Post date:** [May 1, 2009, 8:38am UTC](https://www.ruby-forum.com/t/ssl-accelerator/166787/5 "2009-05-01T08:38:25Z")

</div>

Hmm, that’s kinda hard to do with this block.

```
location / {
  root /var/www/crm;
  access_log off;

  index index.php index.html;
  fastcgi_param SCRIPT_FILENAME /var/www/crm/index.php;

  if (-f $request_filename) {
    expires 1d;
    break;
  }

  try_files $uri $uri/ /index.php?q=$uri;
}

```

I don’t see a way to take out the if block which should serve with  
specific conditions if the file exists.

---

<div class="post-metadata">

**Author:** ![lovewadhwa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bc8723/32.png) [@lovewadhwa](https://www.ruby-forum.com/u/lovewadhwa)\
**Post date:** [May 1, 2009, 8:54am UTC](https://www.ruby-forum.com/t/ssl-accelerator/166787/6 "2009-05-01T08:54:08Z")

</div>

On Fri, May 01, 2009 at 08:38:25AM +0200, Joe Bofh wrote:

> ```
> expires 1d;
> break;
> }
> 
> try_files $uri $uri/ /index.php?q=$uri;
> }
> 
> ```
> 
> I don’t see a way to take out the if block which should serve with  
> specific conditions if the file exists.

```
 location / {
   root /var/www/crm;
   access_log off;

   index index.php index.html;
   expires 1d;

   try_files $uri $uri/ /index.php?q=$uri;
 }

 location ~ \.php$ {
   access_log off;

   fastcgi_param SCRIPT_FILENAME /var/www/crm/index.php;
   fastcgi_pass ...
 }

```

---

<div class="post-metadata">

**Author:** ![lovewadhwa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bc8723/32.png) [@lovewadhwa](https://www.ruby-forum.com/u/lovewadhwa)\
**Post date:** [May 1, 2009, 10:13am UTC](https://www.ruby-forum.com/t/ssl-accelerator/166787/7 "2009-05-01T10:13:35Z")

</div>

Thanks!

For the record, I have this now working with a bunch of different apps  
such as sugarcrm.

```
location / {
  root /var/www/crm;
  access_log off;

  index index.php index.html;
  expires 1d;

  try_files $uri $uri/ /index.php?q=$uri;
}

location ~ \.php$ {
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_index index.php;
  fastcgi_buffer_size 128k;
  fastcgi_buffers 4 256k;
  fastcgi_param SCRIPT_FILENAME /var/www/crm$fastcgi_script_name;
  include /usr/local/nginx/conf/fastcgi_params;
}
```

---

<div class="post-metadata">

**Author:** ![lovewadhwa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bc8723/32.png) [@lovewadhwa](https://www.ruby-forum.com/u/lovewadhwa)\
**Post date:** [May 1, 2009, 10:15am UTC](https://www.ruby-forum.com/t/ssl-accelerator/166787/8 "2009-05-01T10:15:44Z")

</div>

Igor,

While I have your attention, is there a better way to write status  
blocks than the following? I figure this would be useful information for  
everyone.

```
error_page 500 502 503 504 /500.html;
location = /500.html {
  expires 5d;
  root /var/www/crm;
}

error_page 404 /404/index.php;
location = /404/index.php {
  expires 5d;
  root /var/www/crm;
}
```

---

<div class="post-metadata">

**Author:** ![lovewadhwa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bc8723/32.png) [@lovewadhwa](https://www.ruby-forum.com/u/lovewadhwa)\
**Post date:** [May 1, 2009, 10:47am UTC](https://www.ruby-forum.com/t/ssl-accelerator/166787/9 "2009-05-01T10:47:40Z")

</div>

On Fri, May 01, 2009 at 10:15:44AM +0200, Joe Bofh wrote:

> ```
> }
> 
> error_page 404 /404/index.php;
> location = /404/index.php {
> expires 5d;
> root /var/www/crm;
> }
> 
> ```

1. “expires” works only for 200, 204, 301, 302, and 304 responses.
2. /404/index.php will be handled as static file.
3. “root” may be set on server level, if it’s common for server.

---

<div class="post-metadata">

**Author:** ![lovewadhwa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bc8723/32.png) [@lovewadhwa](https://www.ruby-forum.com/u/lovewadhwa)\
**Post date:** [May 1, 2009, 8:04am UTC](https://www.ruby-forum.com/t/ssl-accelerator/166787/10 "2009-05-01T08:04:22Z")

</div>

On Fri, May 01, 2009 at 12:49:21AM +0200, Joe Bofh wrote:

> Igor,
> 
> Can you explain why it’s better to use this format?

Due to unbethought implementation “if” may work not so as you expect.  
Probably, the only natural usage is:

```
 if (...) {
     return 403;
 }

```

and

```
 if (...) {
     rewrite ... last;
 }

```

The following examples

```
 if (...) {
     rewrite ... break;
 }

 if (...) {
     break;
 }

```

have may drawbacks.

As to “upstream”, you do not need it for single upstream server and  
using real host in proxy\_pass allow to use default proxy\_redirect.

With upstream you should add

```
   proxy_redirect http://dev1.magazine.com:8000/ /;

```

because default proxy\_redirect will be without port

```
   proxy_redirect http://dev1.magazine.com/ /;

```
