dockerizing for production
This commit is contained in:
44
nginx.conf.template
Normal file
44
nginx.conf.template
Normal file
@@ -0,0 +1,44 @@
|
||||
upstream api_back {
|
||||
server ${VITE_API_HOST};
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
||||
# Root directory for static files
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# Proxy API requests
|
||||
location /api/ {
|
||||
# IMPORTANT: The resolver is necessary for Nginx to resolve DNS inside a Docker container
|
||||
# when using variables in proxy_pass. 127.0.0.11 is Docker's internal DNS server.
|
||||
# resolver 127.0.0.11;
|
||||
|
||||
# Set headers for the proxied request
|
||||
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;
|
||||
|
||||
# Inject the custom API key header
|
||||
proxy_set_header X-API-KEY '${VITE_API_KEY}';
|
||||
|
||||
# Use environment variables for the proxy target and API key.
|
||||
# These will be substituted by envsubst in the entrypoint script.
|
||||
proxy_pass http://api_back${VITE_API_DIR}/api/;
|
||||
}
|
||||
|
||||
# Serve static files directly
|
||||
location / {
|
||||
# Fallback to index.html for Single Page Application (SPA) routing
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
# Optional: Add error pages for better user experience
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root /usr/share/nginx/html;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user