NginX Newbie.
I want to use NginX as a reverse proxy for websphere libery appserver on the same machine running on port 9080.
I want all requests to come thru NginX and all responses to enable CORs.
I got this to work but there is a lot of repetition in my nginx conf. How do I re-use CORs config across all locations?
server {
listen 80;
server_name $host;
proxy_pass http://localhost:9080;
location = / {
[ CORs configuration ]
}
location /two/ {
[ CORs configuration repeated ]
}
location /three/ {
[ CORs configuration repeated again ]
}
}
You can set cors options in the server block so you don't have to repeat it for every location:
server {
listen 80;
server_name $host;
proxy_pass http://localhost:9080;
add_header 'Access-Control-Allow-Origin' '*';
location = / {...
Excerpt from the nginx documentation:
Syntax: add_header name value [always];
Default: —
Context: http, server, location, if in location
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With