Wouldn't it be less work to set up subdomains and handle this with DNS?
I for one will never qualify for this T shirt.
https://store.xkcd.com/products/i-know-regular-expressions
Original Message
From: paul@stormy.ca
Sent: April 14, 2020 1:39 PM
To: nginx@nginx.org
Reply-to: nginx@nginx.org
Subject: Rewrite -- failure
New to this list (lurked for a couple of weeks), so hope you'll bear
with me. I'm trying to get a charity's volunteers set up to work from home.
Using nginx 1.14.0 (latest on Ubuntu 14.04LTS -- all up to date; #nginx
-V below) as a front end for a number of servers using Apache 2.4.
My problem is that I need to split serv1.example.com to two physical
servers (both fully functional on LAN). The first (192.168.aaa.bbb)
serving static https works fine. But I cannot "rewrite" (redirect,
re-proxy?) to the second server (192.168.xxx.yyy, Perl cgi) where the
request comes in as https://serv1.example.com/foo and I need to get rid
of "foo"
"rewrite ^(.*serv1\.example\.com\/)foo\/(.*) $1$2 permanent;" (tried
permanent, break, last and no flags)
is valid as a PCRE regex, but logs give me a 404 trying to find "foo"
which has nothing to do with the cgi root:
[14/Apr/2020:16:14:19 -0400] "GET /foo HTTP/1.1" 404 2471
What I am trying for is "GET / HTTP/1.1" 200
Here's my server config. Any all assistance would be greatly
appreciated -- many thanks and stay well -- Paul
server {
listen 443 ssl;
# [4 lines managed by Certbot, working perfectly]
server_name serv1.example.com;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/mysite-error_log;
proxy_buffering off;
location / { # static server, html, works perfectly,
proxy_pass http://192.168.aaa.bbb;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /foo { # big db server, perfect on LAN, PERL, cgi
# rewrite ^/foo(.*) /$1 break; #tried permanent, break, last
and no flags
# rewrite ^/foo/(.*)$ /$1 last; #tried permanent, break, last
and no flags
rewrite ^(.*serv1\.example\.com\/)foo\/(.*) $1$2 permanent;
#tried permanent, break, last and no flags
proxy_pass http://192.168.xxx.yyy:8084;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
if ($host = serv1.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
# automatically sets to https if someone comes in on http
listen 80;
listen 8084;
server_name serv1.example.com;
rewrite ^ https://$host$request_uri? permanent;
}
_________
nginx -V
nginx version: nginx/1.14.0 (Ubuntu)
built with OpenSSL 1.1.1 11 Sep 2018
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2
-fdebug-prefix-map=/build/nginx-GkiujU/nginx-1.14.0=.
-fstack-protector-strong -Wformat -Werror=format-security -fPIC
-Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions
-Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx
--conf-path=/etc/nginx/nginx.conf
--http-log-path=/var/log/nginx/access.log
--error-log-path=/var/log/nginx/error.log
--lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid
--modules-path=/usr/lib/nginx/modules
--http-client-body-temp-path=/var/lib/nginx/body
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi
--http-proxy-temp-path=/var/lib/nginx/proxy
--http-scgi-temp-path=/var/lib/nginx/scgi
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit
--with-http_ssl_module --with-http_stub_status_module
--with-http_realip_module --with-http_auth_request_module
--with-http_v2_module --with-http_dav_module --with-http_slice_module
--with-threads --with-http_addition_module
--with-http_geoip_module=dynamic --with-http_gunzip_module
--with-http_gzip_static_module --with-http_image_filter_module=dynamic
--with-http_sub_module --with-http_xslt_module=dynamic
--with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic
--with-mail_ssl_module
\\\||//
(@ @)
ooO_(_)_Ooo__________________________________
|______|_____|_____|_____|_____|_____|_____|_____|
|___|____|_____|_____|_____|_____|_____|_____|____|
|_____|_____| mailto:paul@stormy.ca _|____|____|
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx