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 {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
server_name localhost;
|
server_name localhost;
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
index index.html;
|
||||||
|
|
||||||
# Enable gzip compression
|
# Enable gzip compression
|
||||||
gzip on;
|
gzip on;
|
||||||
@ -12,7 +14,12 @@ server {
|
|||||||
include /etc/nginx/auth.conf;
|
include /etc/nginx/auth.conf;
|
||||||
|
|
||||||
# Serve static files
|
# 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
|
# Handle preflight requests
|
||||||
if ($request_method = 'OPTIONS') {
|
if ($request_method = 'OPTIONS') {
|
||||||
@ -25,6 +32,17 @@ server {
|
|||||||
return 204;
|
return 204;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 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
|
# Proxy requests to the data API
|
||||||
location /data/ {
|
location /data/ {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user