Forum: NGINX Need help optimizing nginx to redirect from HTTP/80 to HTTPS/443

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Mark A. (Guest)
on 2009-02-22 14:09
(Received via mailing list)
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/ ,
should go into:
    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 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 ---
Igor S. (Guest)
on 2009-02-22 14:49
(Received via mailing list)
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/ ,
> should go into:
>    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 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.
Mark A. (Guest)
on 2009-02-22 16:19
(Received via mailing list)
Igor S. wrote:
 >
> 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

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.
This topic is locked and can not be replied to.