K
K
koltykov2014-11-06 14:37:28
Nginx
koltykov, 2014-11-06 14:37:28

How to redirect from https back to http in NGIXNX?

The task is this: where the CMS is found, it should be transferred to the https protocol, and wherever the CMS is not found, it should be transferred to the usual one.
When CMS throws, but does not work back. It only works on directories, it doesn't work on PHP files.
For example https://site1.ru/subfolder/ - redirects to site1.ru/subfolder
And so there is no https://site1.ru/subfolder/file.php

server {
    listen 80;
    server_name site1.net www.site1.net;

    # Папка с контентом сайта
    root /var/www/site1/;

    access_log /var/log/nginx/site1-access.log;
    error_log /var/log/nginx/site1-error.log;

    location ~* ^/cms/(.*)/$ {
       rewrite ^ https://$server_name$request_uri? permanent; 
    }
    rewrite ^([^.\?]*[^/])$ $1/;

    include /etc/nginx/templates/default;
    include /etc/nginx/templates/php;
}
server {
    listen 443 ssl;
    
    ssl         on;
    ssl_protocols       SSLv3 TLSv1;
    ssl_certificate     /etc/nginx/ssl/ssl_site1.crt;
    ssl_certificate_key /etc/nginx/ssl/ssl_site1.key;

    server_name site1.net www.site1.net;

    # Папка с контентом сайта
    root /var/www/site1/;

    access_log /var/log/nginx/ssl_site1-access.log;
    error_log /var/log/nginx/ssl_site1-error.log;

    location ~* ^/cms/(.*)/$ {
        try_files $uri /cms/index.php?q=$1&$query_string;
    }
        
    rewrite ^([^.\?]*[^/])$ $1/;

    location / {
       return 301 http://$server_name$request_uri;
    }

    include /etc/nginx/templates/default;
    include /etc/nginx/templates/php;
}

What am I doing wrong?
Update:
Templates/php config:
# Передаём обработку PHP-скриптов PHP-FPM
location ~ \.php$ {
    #try_files $uri =404; 
    error_page 404 /404.htm;
    fastcgi_pass   unix:/tmp/wwwpool.sock;

    fastcgi_cache one;
    fastcgi_cache_min_uses 5;

    fastcgi_cache_valid 200 301 302 304 5m;

    fastcgi_cache_key "$request_method|$host|$request_uri";

    fastcgi_index index.php;
    fastcgi_intercept_errors on; # только на период тестирования

    include fastcgi_params;

    fastcgi_param       SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_ignore_client_abort     off;

    fastcgi_buffers 16 16k; 
    fastcgi_buffer_size 32k;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
brutal_lobster, 2014-11-07
@brutal_lobster

nginx.org/ru/docs/http/request_processing.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question