Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vaenow/nginx-cors
https://github.com/vaenow/nginx-cors
Last synced: 10 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/vaenow/nginx-cors
- Owner: vaenow
- Created: 2022-04-13T10:19:23.000Z (over 2 years ago)
- Default Branch: feature-cors-dispatcher
- Last Pushed: 2024-07-31T09:28:03.000Z (5 months ago)
- Last Synced: 2024-10-26T07:25:10.814Z (about 2 months ago)
- Language: Shell
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Ngnix CORS Anywhere
Configure Nginx server as a reverse proxy so that inject header `Access-Control-Allow-Origin: '*'` on all responses.
In frontend development, requests from client side Javascript, such as axios.get(targetURL).then(...).catch(...), often
receive `Failed to load : No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://127.0.0.1:8080' is therefore not allowed access.`This docker configure a Nginx server, such that when client sent request to `http://nginx-cors-server/cors/`,
the server proxy_pass and proxy_redirect the request to ``, and when the server receive the response from the
``, the server add header `Access-Control-Allow-Origin: '*'` on the response, and pass it back to client.```
$ docker run --rm -it -p 80:80 gyang274/nginx-cors:1.0.0$ curl -H 'Origin: http://192.168.0.1' -I -X GET http://127.0.0.1/cors/https://www.google.com/
$ curl -H 'Origin: http://192.168.0.1' -I -X GET http://127.0.0.1/cors/https://www.google.com/ --verbose
# note: as above, nginx-cors-server is running on localhost, e.g., http://127.0.0.1/, and a request to targetURL
# https://www.google.com/ is proxy_pass and proxy_redirect by nginx-cors-server, using
# http://127.0.0.1/cors/https://www.google.com/.
```