Nginx Config

I was tried of having to Google this everytime!

Dockerfile

Where to put the nginx.conf inside Nginx, this COPY command is in your Dockerfile.

1
2
3
4
FROM nginx:alpine
FROM nginx:1.9.15-alpine

COPY nginx.conf /etc/nginx/conf.d/default.conf

Reverse proxy

A reverse proxy provides an additional level of abstraction and control to ensure the smooth flow of network traffic between clients and servers.

1
2
3
4
5
server {
location / {
proxy_pass http://localhost:5000;
}
}

React App 404 on refresh

The react app manages the route but then a refresh on a route that Nginx pulls a WFT is this on returns 404 -_-

1
2
3
4
5
server {
location / {
try_files $uri /index.html;
}
}

Complete Sample config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
server {
listen 80;
server_name localhost;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri /index.html;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}