config: enhance nginx with CORS headers and proper root directory setup
This commit is contained in:
parent
214491c1dc
commit
4dd08654c8
20
nginx.conf
20
nginx.conf
@ -1,6 +1,8 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# Enable gzip compression
|
||||
gzip on;
|
||||
@ -12,7 +14,12 @@ server {
|
||||
include /etc/nginx/auth.conf;
|
||||
|
||||
# Serve static files
|
||||
try_files $uri $uri/ /index.html;
|
||||
try_files $uri $uri/ =404;
|
||||
|
||||
# CORS headers
|
||||
add_header 'Access-Control-Allow-Origin' '*' always;
|
||||
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
|
||||
add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization' always;
|
||||
|
||||
# Handle preflight requests
|
||||
if ($request_method = 'OPTIONS') {
|
||||
@ -26,6 +33,17 @@ server {
|
||||
}
|
||||
}
|
||||
|
||||
# Special location for index.html to avoid redirection loops
|
||||
location = /index.html {
|
||||
# Include authentication configuration
|
||||
include /etc/nginx/auth.conf;
|
||||
|
||||
# CORS headers
|
||||
add_header 'Access-Control-Allow-Origin' '*' always;
|
||||
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
|
||||
add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization' always;
|
||||
}
|
||||
|
||||
# Proxy requests to the data API
|
||||
location /data/ {
|
||||
proxy_pass http://localhost:3000/data/;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user