-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnginx.conf
97 lines (75 loc) · 3.23 KB
/
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# /etc/nginx/nginx.conf
#Sets the number of worker processes based on CPU cores available
worker_processes auto;
pid /var/run/nginx.pid;
events {
#Handles how many connections each worker process can handle simutaneously
worker_connections 1024;
}
#Handles requests for the vue static files
http {
#Loads the mime types file that defines mappings between file extensions and content types
include /etc/nginx/mime.types;
default_type application/octet-stream;
#Enables the sendFile system call that handles file transfers faster
sendfile on;
#Time in seconds that Nginx should keep a connection open after finishing a request
keepalive_timeout 65;
map $http_origin $cors_origin {
default ""; # Default to disallow all origins
"http://localhost:8080" "http://localhost:8080";
"http://127.0.0.1:8080" "http://127.0.0.1:8080";
"https://sherlock-dev.tamucc.edu/semaphore-api" "https://sherlock-dev.tamucc.edu/semaphore-api";
"https://sherlock-prod.tamucc.edu/semaphore-api" "https://sherlock-prod.tamucc.edu/semaphore-api";
}
server {
#Nginx listens on port 80
listen 80;
#Sets the servername - Need to change to the reverse proxy/host name in production
server_name frontend;
root /usr/share/nginx/html;
# / is mapped with root
location /flare/ {
index index.html;
try_files $uri $uri/ /index.html;
# CORS headers
add_header Access-Control-Allow-Origin $cors_origin always;
add_header Access-Control-Allow-Methods "GET, OPTIONS";
add_header Access-Control-Allow-Headers "Content-Type, Authorization";
# Handle preflight OPTIONS requests
if ($request_method = 'OPTIONS') {
add_header Access-Control-Allow-Origin $cors_origin always;
add_header Access-Control-Allow-Methods "GET, OPTIONS";
add_header Access-Control-Allow-Headers "Content-Type, Authorization";
return 204;
}
}
# Serve static files (JS, CSS, images)
location /flare/assets/ {
alias /usr/share/nginx/html/assets/; # Map /flare/assets/ to the correct directory
try_files $uri =404; # Return 404 if the file doesn't exist
}
# Serve CSV data files
location /flare/csv-data/ {
alias /app/data/csv/;
autoindex on;
# Ensure only existing files are served
try_files $uri =404;
# CORS headers for CSV
add_header Access-Control-Allow-Origin $cors_origin always;
add_header Access-Control-Allow-Methods "GET, OPTIONS";
add_header Access-Control-Allow-Headers "Content-Type";
if ($request_method = 'OPTIONS') {
add_header Access-Control-Allow-Origin $cors_origin always;
add_header Access-Control-Allow-Methods "GET, OPTIONS";
add_header Access-Control-Allow-Headers "Content-Type";
return 204;
}
}
# Handle errors
error_page 404 /404.html;
location = /404.html {
internal;
}
}
}