Last active
January 15, 2018 20:41
-
-
Save StevenJL/2d5d6fc22ead4c86201bbc4887f1aaff to your computer and use it in GitHub Desktop.
Named Location
This file contains hidden or 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
http { | |
server { | |
upstream upstream_server { | |
server unix:/tmp/rails.sock; | |
} | |
# This defines a "named location" called @proxy, which can be | |
# referenced elsewhere in this configuration. It's sort of like | |
# a variable for locations. | |
location @proxy { | |
proxy_pass http://upstream_server; | |
# The `proxy_set_header` directive is used to pass headers to the | |
# upstream server. In this case, we pass along the host of the original | |
# server that first processed the request. | |
proxy_set_header HOST $host; | |
# Similarly, we pass the ip address of the client to the upstream server. | |
proxy_set_header X-Real-IP $ remote_addr; | |
} | |
location / { | |
# The `try_files` takes a list of files an a location as the last argument. | |
# The $uri is a special variable that refers to the URI of the request. | |
# Basically for every request, we will try to find/directory the file that | |
# matches the URI and if it's not found, we forward the request to the upstream | |
# server. | |
try_files $uri $uri/ @proxy; | |
} | |
} | |
} | |
# vim: ft=nginx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment