Skip to content

Instantly share code, notes, and snippets.

@alexfedoseev alexfedoseev/hosts Secret
Created Jul 23, 2015

Embed
What would you like to do?
Nginx config & hosts file on localhost
# /private/etc/hosts
fe80::1%lo0 lvh.me
fe80::1%lo0 api.lvh.me
127.0.0.1 lvh.me
127.0.0.1 api.lvh.me
# /usr/local/etc/nginx/nginx.conf
upstream app_proxy {
server 127.0.0.1:3500;
}
upstream api_proxy {
server 127.0.0.1:3000;
}
server {
listen 80;
server_name lvh.me;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-forwarded-for $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://app_proxy;
proxy_redirect off;
}
location /api {
proxy_set_header Host api.lvh.me;
proxy_set_header X-forwarded-for $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://api_proxy/;
proxy_redirect off;
}
}
server {
listen 80;
server_name api.lvh.me;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-forwarded-for $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://api_proxy;
proxy_redirect off;
}
}
@Kshitij-Banerjee

This comment has been minimized.

Copy link

Kshitij-Banerjee commented May 24, 2016

The nginx.conf needs to be wrapped in a http {} ... and have to specify events.

@Kshitij-Banerjee

This comment has been minimized.

Copy link

Kshitij-Banerjee commented May 24, 2016

for folks using webbrick.. also have to add localhost mapping to the hosts file.

@ghost

This comment has been minimized.

Copy link

ghost commented Oct 7, 2016

thanks for pointing this out. I was having the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.