Files
srv-pub/cfg/ngx/fw.op.fo.conf

110 lines
3.4 KiB
Plaintext
Raw Normal View History

2025-10-29 03:01:59 -05:00
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# configuration of fw.op.fo / frode klevstul / oct 2025
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2025-10-29 03:38:11 -05:00
# sc.op.fo ➔ fw.op.fo
server {
listen 80;
server_name sc.op.fo;
return 301 https://fw.op.fo$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
ssl_certificate /etc/nginx/acme.sh/op.fo/fullchain.pem;
ssl_certificate_key /etc/nginx/acme.sh/op.fo/key.pem;
ssl_trusted_certificate /etc/nginx/acme.sh/op.fo/cert.pem;
2025-10-29 03:38:59 -05:00
server_name sc.op.fo;
2025-10-29 03:38:11 -05:00
return 301 https://fw.op.fo$request_uri;
}
2025-10-29 03:01:59 -05:00
# http to https
server {
listen 80;
server_name fw.op.fo;
return 301 https://$host$request_uri;
}
2025-10-29 03:14:54 -05:00
# upstream configuration for postgrest (used as reversed proxy)
upstream postgrest {
2025-10-29 05:28:16 -05:00
server localhost:3000;
2025-10-29 03:14:54 -05:00
}
2025-10-29 03:11:03 -05:00
2025-10-29 03:40:05 -05:00
# https
2025-10-29 03:01:59 -05:00
server {
listen 443 ssl;
listen [::]:443 ssl;
http2 on;
ssl_certificate /etc/nginx/acme.sh/op.fo/fullchain.pem;
ssl_certificate_key /etc/nginx/acme.sh/op.fo/key.pem;
ssl_trusted_certificate /etc/nginx/acme.sh/op.fo/cert.pem;
add_header Strict-Transport-Security "max-age=63072000" always;
root /var/www/fw.op.fo;
index index.html;
server_name fw.op.fo;
location @myownredirect {
return 302 /;
}
2025-10-29 03:11:03 -05:00
# postgrest reverse proxy
2025-10-29 03:14:54 -05:00
location / {
2025-10-29 03:28:06 -05:00
error_page 404 = @myownredirect;
2025-10-29 03:11:03 -05:00
}
2025-10-29 05:59:58 -05:00
# /dbg/shortcode | debug mode
2025-10-29 04:36:17 -05:00
location ~ ^/dbg/(\w+) {
2025-10-29 04:35:07 -05:00
default_type application/json;
proxy_hide_header Content-Location;
add_header Content-Location /rpc/$upstream_http_content_location;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
2025-10-29 04:36:17 -05:00
proxy_pass http://postgrest/rpc/fwd?p_shortcode=$1&p_dbg=true;
2025-10-29 04:35:07 -05:00
}
2025-10-29 05:59:58 -05:00
# /shortcode | normal mode
location ~ ^/([A-Za-z0-9]+) {
# https://stackoverflow.com/questions/53353572/proxy-pass-cannot-have-uri-part-in-location-given-by-regular-expression
rewrite ^/([A-Za-z0-9]+) /rpc/fwd break;
default_type application/json;
proxy_hide_header Content-Location;
add_header Content-Location /rpc/$upstream_http_content_location;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_method POST; # note, that if writing 'post' (lowercase) instead of 'POST' (uppercase), that will lead to the postgrest error "cannot use the post method on rpc"
2025-10-29 06:05:08 -05:00
# set $query_string $args;
# proxy_set_body $query_string;
#https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_set_body
2025-10-29 06:09:57 -05:00
proxy_set_body '{"p_shortcode": "ph25", "p_dbg": "true"}';
2025-10-29 06:05:08 -05:00
2025-10-29 05:59:58 -05:00
proxy_pass http://postgrest;
}
2025-10-29 05:28:16 -05:00
2025-10-29 05:01:17 -05:00
# normal mode: /shortcode
2025-10-29 05:34:02 -05:00
# location ~ ^/\w+ {
# #rewrite ^/your_endpoint(.*)$ /your_backend_endpoint?args=$args break;
# #rewrite ^ /your_backend_endpoint?args=$args break;
# default_type application/json;
# proxy_hide_header Content-Location;
# add_header Content-Location /rpc/$upstream_http_content_location;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_http_version 1.1;
# proxy_method post;
## proxy_pass http://postgrest/rpc/fwd?args=$args;
## proxy_pass http://postgrest/rpc/fwd;
# proxy_pass http://postgrest;
# proxy_set_body $args;
# }
2025-10-29 03:28:06 -05:00
2025-10-29 03:01:59 -05:00
}