Skip to content

Instantly share code, notes, and snippets.

@ezzhood
Last active September 23, 2022 09:52
Show Gist options
  • Save ezzhood/e26f76d1a5fde88f91fe6988c66219f5 to your computer and use it in GitHub Desktop.
Save ezzhood/e26f76d1a5fde88f91fe6988c66219f5 to your computer and use it in GitHub Desktop.
Source code for medium nginx configuration article
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# serve static frontend first
try_files $uri $uri/ /index.html;
}
# location ~*^/(api|posts|products) {
location /api {
proxy_pass http://localhost:4000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
@lylest
Copy link

lylest commented Aug 12, 2022

the backend URL become un accesible for someone made request like get or post

@lylest
Copy link

lylest commented Aug 12, 2022

forexample mysite.com/api/post is not working

@ezzhood
Copy link
Author

ezzhood commented Aug 13, 2022

In location /api block all requests beginning with /api are sent to http://localhost:4000. For e.g.: GET mysite.com/api/apples -> GET localhost:4000/api/apples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment