Last active
August 9, 2024 06:08
-
-
Save JarenGlover/d7ffab312ea756834218 to your computer and use it in GitHub Desktop.
Nginx - Reverse Proxy | Backend & Front End Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream fuel { | |
# Defines a group of servers. Servers can listen on different ports. | |
server IP:PORT fail_timeout=0; | |
} | |
upstream frontend { | |
server IP:PORT fail_timeout=0; | |
} | |
server { | |
listen IP:80; | |
# domains and IP address you want to serve | |
server_name .data.jarenglover.com SERVER_IP_ADDRESS; | |
access_log /path/to/log/on/server/nginx_access.log; # set your logs | |
# note: uses diff logs for diff sub domains | |
error_log /path/to/log/on/server/nginx_error.log; | |
location / { | |
# requests on '/' will be proxy_pass | |
#proxy server for sending data to node.js | |
proxy_pass http://frontend; | |
} | |
location /img { | |
# remember let nginx handle static files not app code | |
root /path/to/static/files/frontend/app/; | |
} | |
location /api { | |
# requests to the API will be proxy_pass to the backend API infra | |
# read this -> http://en.wikipedia.org/wiki/X-Forwarded-For | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
# pass the host header from the client to help with redirects | |
proxy_set_header Host $http_host; | |
# stops nginx from doing something silly | |
proxy_redirect off; | |
# proxy_pass to backend API Django in my case | |
proxy_pass http://api; | |
# send the IP address and remote server address for secuirty | |
proxy_set_header X-Real-IP $remote_addr; | |
# Adds headers to the HTTP response | |
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"'; | |
} | |
} | |
server { | |
# If the remote server is not listed its goes to the default_server | |
listen IP:PORT default_server; | |
return 404; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment