Answer the question
In order to leave comments, you need to log in
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;
}
# Передаём обработку 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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question