S
S
saanneekk2015-02-06 17:11:13
Nginx
saanneekk, 2015-02-06 17:11:13

How to set up an http to https redirect in ISPManager 4?

You need to redirect from the http https version of the site. Website Wordpress 4.1, VPS on DigitalOcean, ISPManager 4.
Backend - Apache, Frontend - nginx.
After much torment, it turned out to redirect all pages of the site except the main one, in fact, this is the problem. On the main cyclic forwarding.
nginx config

server {
    server_name example.com.ua www.example.com.ua;
    listen 95.34.6.59:80;
    rewrite ^ https://$host$request_uri? permanent;
    
    disable_symlinks if_not_owner from=$root_path;
    index index.php;
    set $root_path /bla/bla/example.com.ua;
    location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
      root $root_path;
      access_log /bla/bla/nginx-logs/ isp;
      access_log /bla/bla/httpd-logs/example.com.ua.access.log ;
      error_page 404 = @fallback;
    }
    location / {
      proxy_pass http://95.85.6.59:81;
      proxy_redirect http://95.85.6.59:81/ /;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Real-IP $remote_addr;
      
    }
    location ~* ^/(webstat|awstats|webmail|myadmin|pgadmin)/ {
      proxy_pass http://95.85.6.59:81;
      proxy_redirect http://95.85.6.59:81/ /;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Real-IP $remote_addr;
    }
    location @fallback {
      proxy_pass http://95.85.6.59:81;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Real-IP $remote_addr;
    }
    location ~* ^.+\.(html|jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf|ttf|woff|otf)$ {
      root $root_path;
      access_log /bla/bla/nginx-logs/ isp;
      access_log /bla/bla/httpd-logs/access.log ;
      error_page 404 = @fallback;
    }
    location ^~ /webstat/ {
      auth_basic "Restricted area";
      auth_basic_user_file /bla/bla/data/etc/802063.passwd;
      try_files $uri @fallback;
    }
    include /bla/bla/etc/nginx.inc;
    
  }
  server {
    server_name example.com.ua www.example.com.ua;
    
    listen 95.85.6.59:443 ssl;
    
    disable_symlinks if_not_owner from=$root_path;
    index index.php;
    set $root_path /bla/bla/www/example.com.ua;
    location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
      root $root_path;
      access_log /bla/bla/nginx-logs/ isp;
      access_log /bla/bla/httpd-logs/example.com.ua.access.log ;
      error_page 404 = @fallback;
    }
    location / {
      proxy_pass http://95.85.6.59:81;
      proxy_redirect http://95.85.6.59:81/ /;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Real-IP $remote_addr;
      
    }
    location ~* ^/(webstat|awstats|webmail|myadmin|pgadmin)/ {
      proxy_pass http://95.85.6.59:81;
      proxy_redirect http://95.85.6.59:81/ /;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Real-IP $remote_addr;
    }
    location @fallback {
      proxy_pass http://95.85.6.59:81;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Real-IP $remote_addr;
    }
    location ~* ^.+\.(html|jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf|ttf|woff|otf)$ {
      root $root_path;
      access_log /bla/bla/nginx-logs/ isp;
      access_log /bla/bla/httpd-logs/access.log ;
      error_page 404 = @fallback;
    }
    location ^~ /webstat/ {
      auth_basic "Restricted area";
      auth_basic_user_file /bla/bla/data/etc/802063.passwd;
      try_files $uri @fallback;
    }
    include /usr/local/ispmgr/etc/nginx.inc;
    ssl_certificate /bla/bla/fhggf.crt;
    ssl_certificate_key /bla/bla/httpd-cert/fghfd.key;
  }

apache config
<VirtualHost 95.85.6.59:81 >
  ServerName example.com.ua
  CustomLog /var/www/httpd-logs/example.com.ua.access.log combined
  DirectoryIndex index.php
  DocumentRoot /bla/bla/data/www/example.com.ua
  ErrorLog /var/www/httpd-logs/example.com.ua.error.log
  ServerAdmin [email protected]
  ServerAlias www.example.com.ua
  SuexecUserGroup domains domains
  AddHandler fcgid-script .php .php3 .php4 .php5 .phtml
  ScriptAlias /cgi-bin/ /bla/bla/data/www/example.com.ua/cgi-bin/
</VirtualHost>

.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

I've been suffering for 3 days already.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Fateev, 2015-02-06
@svfat

You have a lot of things in the config of the first server, if you want to redirect all HTTP requests to HTTPS, it will be enough just:

server {
      listen      95.34.6.59:80 default;
      server_name example.com.ua www.example.com.ua;
      rewrite        ^ https://$server_name$request_uri? permanent;
}

S
saanneekk, 2015-02-06
@saanneekk

and I’ll add, at the entrance to the admin panel, too, the 310th

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question