Answer the question
In order to leave comments, you need to log in
Setting up a redirect to https nginx?
The task is to redirect to https at the nginx level, but one /test/* subsection must work on http. There is a config with a redirect of all sections to https
server {
server_name test.ru www.test.ru;
charset UTF-8;
disable_symlinks if_not_owner from=$root_path;
index index.html index.php;
root $root_path;
set $root_path /var/www/test/data/www/test.ru;
access_log /var/www/httpd-logs/test.ru.access.log ;
error_log /var/www/httpd-logs/test.ru.error.log notice;
include /etc/nginx/vhosts-includes/*.conf;
location / {
location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
try_files $uri $uri/ @fallback;
expires 3d;
}
location / {
try_files /does_not_exists @fallback;
}
location ~ [^/]\.ph(p\d*|tml)$ {
try_files /does_not_exists @fallback;
}
}
location @fallback {
proxy_pass http://127.0.0.1:8080;
proxy_redirect http://127.0.0.1:8080 /;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
access_log off ;
}
ssi on;
listen 99.99.999.999:80;
return 301 https://$host$request_uri;
}
Answer the question
In order to leave comments, you need to log in
Maybe I'm not getting it, but you have something incomprehensible here. A bunch of locations, and at the end - a redirect. And why then is there a bunch of locations (+ nested locations)? This bunch still doesn't work.
server {
listen 99.99.999.999:80;
server_name test.ru www.test.ru;
index index.html index.php;
access_log /var/www/httpd-logs/test-test.ru.access.log ;
error_log /var/www/httpd-logs/test-test.ru.error.log;
location /test/ {
root /var/www/test/data/www/test.ru;
#Тут параметры для локейшна test и т.д.
}
location / {
return 301 https://test.ru$request_uri;
}
}
the raisin in nginx configs is that the location is chosen with the highest match (except for locations with regexps). so read above answer
Thank you all, the xtreme solution is correct, in the comments to the post, I posted what worked for me
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question