# Need help optimizing nginx to redirect from HTTP/80 to HTTPS/443

**URL:** <https://www.ruby-forum.com/t/need-help-optimizing-nginx-to-redirect-from-http-80-to-https-443/161022>\
**Category:** NGINX\
**Created:** [February 22, 2009, 1:09pm UTC](https://www.ruby-forum.com/t/need-help-optimizing-nginx-to-redirect-from-http-80-to-https-443/161022 "2009-02-22T13:09:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![larios](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bc79bd/32.png) [@larios](https://www.ruby-forum.com/u/larios)\
**Post date:** [February 22, 2009, 1:09pm UTC](https://www.ruby-forum.com/t/need-help-optimizing-nginx-to-redirect-from-http-80-to-https-443/161022/1 "2009-02-22T13:09:02Z")

</div>

I am trying to optimize Nginx (Nginx/0.6.35 + Ubuntu 8.10) to redirect  
from HTTP/80 to HTTPS/443

I.e., any calls made to:  
[http://pma.clinicacgm.0/](http://pma.clinicacgm.0/) ,  
should go into:  
[https://pma.clinicacgm.0/](https://pma.clinicacgm.0/)

Could you review the bellow attached script and see if it can be  
optimized?

Thank you,

M.

# — cut here —

# /etc/nginx/sites-available/spma

server {  
listen pma.clinicacgm.0:80;  
server\_name pma.clinicacgm.0;

# redirect phpmyadmin to the https page

location / {  
# redirect to secure page [permanent | redirect]  
rewrite ^/(.\*) [https://pma.clinicacgm.0](https://pma.clinicacgm.0) permanent;  
}  
}  
server {  
listen pma.clinicacgm.0:443;  
server\_name pma.clinicacgm.0;

access\_log /var/log/nginx/pma.access.log;  
error\_log /var/log/nginx/pma.error.log;

#root /var/www/phpmyadmin;  
root /usr/share/phpmyadmin;

location / {  
index index.php;  
include /etc/nginx/fastcgi\_params;  
fastcgi\_pass unix:/tmp/php-fastcgi.socket;  
fastcgi\_index index.php;  
fastcgi\_param SCRIPT\_FILENAME $document\_root$fastcgi\_script\_name;  
fastcgi\_param HTTPS on;  
}

gzip off; # gzipping SSL encripted data is a waste of time  
ssl on;  
ssl\_certificate /etc/nginx/ssl/clinicacgm/server.crt;  
ssl\_certificate\_key /etc/nginx/ssl/clinicacgm/server.key;

}

# — cut here —

---

<div class="post-metadata">

**Author:** ![larios](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bc79bd/32.png) [@larios](https://www.ruby-forum.com/u/larios)\
**Post date:** [February 22, 2009, 1:49pm UTC](https://www.ruby-forum.com/t/need-help-optimizing-nginx-to-redirect-from-http-80-to-https-443/161022/2 "2009-02-22T13:49:01Z")

</div>

On Sun, Feb 22, 2009 at 11:55:39AM +0000, Mark A. wrote:

> I am trying to optimize Nginx (Nginx/0.6.35 + Ubuntu 8.10) to redirect  
> from HTTP/80 to HTTPS/443
> 
> I.e., any calls made to:  
> [http://pma.clinicacgm.0/](http://pma.clinicacgm.0/) ,  
> should go into:  
> [https://pma.clinicacgm.0/](https://pma.clinicacgm.0/)

Do you want to redirect

```
http://pma.clinicacgm.0/some/uri to just

https://pma.clinicacgm.0/

```

or to

```
https://pma.clinicacgm.0/some/uri

```

?

> server {  
> listen pma.clinicacgm.0:80;  
> server\_name pma.clinicacgm.0;
> 
> # redirect phpmyadmin to the https page
> 
> location / {  
> # redirect to secure page [permanent | redirect]  
> rewrite ^/(.\*) [https://pma.clinicacgm.0](https://pma.clinicacgm.0) permanent;

```
 rewrite ^ https://pma.clinicacgm.0/ permanent;

```

or if you want to preserve URI:

```
 rewrite ^ https://pma.clinicacgm.0$request_uri? permanent;

```

> root /usr/share/phpmyadmin;
> 
> location / {  
> index index.php;

You do not need “index index.php” here as all requests are passed to  
fastcgi.

---

<div class="post-metadata">

**Author:** ![larios](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bc79bd/32.png) [@larios](https://www.ruby-forum.com/u/larios)\
**Post date:** [February 22, 2009, 3:19pm UTC](https://www.ruby-forum.com/t/need-help-optimizing-nginx-to-redirect-from-http-80-to-https-443/161022/3 "2009-02-22T15:19:17Z")

</div>

Igor S. wrote:

> Do you want to redirect  
> [http://pma.clinicacgm.0/some/uri](http://pma.clinicacgm.0/some/uri) to just [https://pma.clinicacgm.0/](https://pma.clinicacgm.0/)  
> or to  
> [https://pma.clinicacgm.0/some/uri](https://pma.clinicacgm.0/some/uri)

Both.

> ```
> rewrite ^ https://pma.clinicacgm.0/ permanent;
> 
> ```
> 
> or if you want to preserve URI:  
> rewrite ^ https://pma.clinicacgm.0$request\_uri? permanent;

Thank you. Both work and do their different jobs as intended.

> > ```
> > index index.php;
> > 
> > ```
> 
> You do not need “index index.php” here as all requests are passed to fastcgi.

You are right. It shouldn’t be there in the first place.

Thank you very much for the fast response.

M.
