Last active
September 23, 2022 09:52
-
-
Save ezzhood/e26f76d1a5fde88f91fe6988c66219f5 to your computer and use it in GitHub Desktop.
Source code for medium nginx configuration article
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
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; | |
} | |
} |
forexample mysite.com/api/post is not working
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
the backend URL become un accesible for someone made request like get or post