koplenov
(koplenov)
December 31, 2022, 1:21am
1
1. Output of caddy version
:
v2.6.2 h1:wKoFIxpmOJLGl3QXoo6PNbYvGW4xLEgo32GPBEjWL8o=
2. How I run Caddy:
systemctl restart caddy
a. System environment:
debian 11
My complete Caddy config:
doman.com {
@path path /?_escaped_fragment_=
handle @path {
reverse_proxy @path localhost:3000
}
root * /usr/share/nginx/static
handle {
file_server
}
}
3. The problem I’m having:
I have a domain, the server should give statics, but on a certain url should go to the proxy server
/ - statics
/?escaped_fragment = - proxy
this config doesn’t work like it should
I checked a lot of configurations, no help
Here is my nginx file:
map $args $prerender_args {
"~(^|&)_escaped_fragment_=" 1;
}
map $http_x_prerender $x_prerender {
default $prerender_args;
"1" 0;
}
map $uri $prerender {
default $x_prerender;
"~*.(js|css|xml|less|png|jpg|jpeg|gif|pdf|doc|txt|ico|rss|zip|mp3|rar|exe|wmv|doc|avi|ppt|mpg|mpeg|tif|wav|mov|psd|ai|xls|mp4|m>
}
server {
server_name scout.hyoo.ru;
root /usr/share/nginx/scout.hyoo.ru/static/;
location / {
if ($prerender = 1) {
rewrite (.*) /prerenderio last;
}
try_files $uri /index.html = 404;
}
location /prerenderio {
if ($prerender = 0) {
return 404;
}
proxy_hide_header Cache-Control;
add_header Cache-Control "private,max-age=600,must-revalidate";
#resolve using Google's DNS server to force DNS resolution and prevent caching of IPs
resolver 8.8.8.8.8.4.4;
set $prerender_host "127.0.0.1:3000";
proxy_pass http://$prerender_host;
rewrite .* /$scheme://$host$request_uri? break;
}
4. Error messages and/or full log output:
Does work
gyfer
( )
January 1, 2023, 12:01pm
2
From my understanding, you are trying to match “https://scout.hyoo.ru/~&_escaped_fragment_= ” from expression "~(^|&)_escaped_fragment_="
in your Nginx config , reverse_proxy it to your server at "http://127.0.0.1:3000/prerenderio/_escaped_fragment_= ? " based on your rewrite rewrite .* /$scheme://$host$request_uri? break;
Here is my take, but I didn’t try
scout.local {
root * /usr/share/nginx/scout.hyoo.ru/static/
@prerender_args {
expression {path}.matches("(?i)/(^|&)_escaped_fragment_=")
not path /prerender*
}
handle @prerender_args {
rewrite / /prerenderio{uri}
}
@prerender {
path /prerenderio/*
expression {path}.matches("(?i)/(^|&)_escaped_fragment_=")
path_regexp ^/\.(js|css|xml|less|png|jpg|jpeg|gif|pdf|doc|txt|ico|rss|zip|mp3|rar|exe|wmv|doc|avi|ppt|mpg|mpeg|tif|wav|mov|psd|ai|xls|mp4)$
}
handle @prerender {
route {
header +Cache-Control "private,max-age=600,must-revalidate"
reverse_proxy http://127.0.0.1:3000 {
rewrite /{uri}$3F
}
}
}
file_server
try_files {path} {path} /index.html =404
}
1 Like
koplenov
(koplenov)
January 1, 2023, 7:27pm
3
doesn’t work.
No, https://scout.hyoo.ru/~&_escaped_fragment_=
→ https://127.0.0.1:3000/https://scout.hyoo.ru/~&_escaped_fragment_=
or https://127.0.0.1:3000/https://scout.hyoo.ru
We need to pass on the entire link
matt
(Matt Holt)
January 1, 2023, 11:38pm
4
Just to make sure we’re clear, https://scout.hyoo.ru/~&_escaped_fragment_=
is the actual, literal (i.e. not decoded) URL you want to match?
koplenov
(koplenov)
January 1, 2023, 11:58pm
5
https://scout.hyoo.ru/?_escaped_fragment_=
- yes
matt
(Matt Holt)
January 2, 2023, 6:08am
6
Ok; so, the path on that URL is /
. The query string is ?_escaped_fragment=
, but the path matcher doesn’t match query strings.
What you can do is combine them:
@proxy {
path /
query _escaped_fragment=
}
handle @proxy ...
Or something like that.
1 Like
koplenov
(koplenov)
January 2, 2023, 11:29pm
7
scout.hyoo.ru {
root * /usr/share/nginx/scout.hyoo.ru/static/
@prerender {
path /
query _escaped_fragment=
}
route @prerender {
redir https://google.com
}
file_server
try_files {path} {path} /index.html =404
}
Not work
in both cases it gives away static
as if the query condition does not work
matt
(Matt Holt)
January 3, 2023, 12:11am
8
Sorry, I omitted a _
in my example, which your config is also missing… please double-check and try again!
Also, try_files
has a higher directive order than route
, so that rewrite will happen first, causing the path /
matcher to no longer match. You don’t need route
in this case. Try this instead:
@prerender {
path /
query _escaped_fragment=
}
redir @prerender https://google.com
1 Like
matt
(Matt Holt)
January 3, 2023, 4:36am
10
(but with the _
added in there )
1 Like
system
(system)
Closed
January 30, 2023, 1:21am
11
This topic was automatically closed after 30 days. New replies are no longer allowed.