Skip to content

Commit

Permalink
Add api.lipas.fi nginx config for prod
Browse files Browse the repository at this point in the history
  • Loading branch information
vharmain committed Dec 28, 2024
1 parent 886028a commit e197696
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions nginx/proxy.conf
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,107 @@ server {
}

}

# Public API via api.lipas.fi
# Server block for api.lipas.fi
server {
listen 443 ssl;
server_name api.lipas.fi;

root /usr/share/nginx/html;

ssl_certificate /certs/server.crt;
ssl_certificate_key /certs/server.key;

# Add security headers
add_header X-Robots-Tag "noindex, nofollow, nosnippet, noarchive";

# Enable compression
gzip on;
gzip_vary on;
gzip_http_version 1.0;
gzip_comp_level 6;
gzip_min_length 1024;
gzip_types application/javascript application/json application/transit+json;

# Route v1 requests to legacy-api
location /v1/ {
proxy_pass http://legacy-api/api/;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
send_timeout 300;

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

# CORS headers
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
}
}

# Route v2 requests to backend
location /v2/ {
proxy_pass http://backend/v2/;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
send_timeout 300;

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

# CORS headers
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
if ($request_method ~* "(GET|POST|PUT|DELETE)") {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
}
}

# Serve API documentation at root
location = / {
try_files /api.html =404;
add_header Content-Type "text/html";
}
}

# HTTP to HTTPS redirect for api.lipas.fi
server {
listen 80;
server_name api.lipas.fi;
return 301 https://$server_name$request_uri;
}

0 comments on commit e197696

Please sign in to comment.