server { server_name www.example.com; listen *:80; listen [::]:80 ipv6only=on; if ($uri !~* ^/downloads/(.+)$) { return 301 https://example.com/downloads/$1; } }
if
лучше использовать location.server {
server_name example.com www.example.com;
listen *:80;
listen [::]:80 ipv6only=on;
location / {
return 301 https://example.com$request_uri;
}
location /downloads/ {
root /var/www/html;
}
}
location ~ ^/i/imgs?/(.*)$ {
resolver 8.8.8.8;
proxy_pass https://$1;
}
location ~ ^/i/imgs?/img\.site2\.ru/(.*)$ {
proxy_pass https://img.site2.ru/$1;
}
server {
listen 80;
listen [::]:80; #Added IPv6 here too
# for certbot
location ^~ /.well-known/acme-challenge/ {
root /etc/nginx/ssl/coins;
}
location / {
return 301 https://my.cryptonot.io$request_uri;
}
}
rewrite ^/index$ / permanent;
rewrite ^(.+)/index$ $1 permanent;
rewrite ^/((.+)/)?index$ /$2 permanent;
location ~ \.php$ {
try_files $uri =404;
location ~ ^/(.*\.php)$ {
try_files $uri /index.php?_route_=$1;
server {
listen *:12901;
server_name test.lan;
location / {
proxy_pass http://lan_nodes;
//....
}
location ~ ^/static/.*\.(jpg|jpeg|gif|png|webp|ico|css|bmp|swf|js|html|txt|ejs|json)$ {
root /test/vendor;
expires 10d;
}
location ~ \.(jpg|jpeg|gif|png|webp|ico|css|bmp|swf|js|html|txt|ejs|json)$ {
root /test/app/dist/images;
expires 10d;
}
}
rewrite ^/index.video$ /index.html;
location = /index.video {
try_files /index.html =404;
}
Необходимо иметь в виду, что при использовании индексного файла делается внутреннее перенаправление и запрос может быть обработан уже в другом location’е. Например, в такой конфигурации:location = / { index index.html; } location / { ... }
запрос “/” будет фактически обработан во втором location’е как “/index.html”.
location = /
вместо index нужен try_files.server {
listen 80;
server_name localhost;
index index.html;
root C:/Workspace/landing;
location = / {
try_files /index.html =404;
}
location /images/ { }
location /css/ { }
location /js/ { }
location / {
root C:/Workspace/frontend/dist/app-frontend;
try_files $uri $uri/ /index.html;
}
}
location /internal_redirect/ {
proxy_pass http://google.com/;
}
location /internal_redirect/ {
rewrite ^/internal_redirect/(.*) /$1 break;
proxy_pass http://google.com;
}
upstream api {
server 127.0.0.1:7777;
}
server {
listen 80;
listen [::]:80;
server_name example.com;
root /home/iam/project/dist;
location / {
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_pass http://api/;
}
location /static/ {
try_files $uri @cdn_uploads;
}
location @cdn_uploads {
root /home/iam/cdn/uploads;
rewrite ^/static(/.*)$ $1 break;
}
}