Comments (4)
try using another configuration approach to rewrites. You may find an example here: https://github.com/nginxinc/ansible-role-nginx-config/blob/main/molecule/default/converge.yml#L594
In general though it seems like you don't need a rewrite. Just make all the locations prefix (get rid of '~') and then add forward slash in the proxy statement where you wanted the rewrite.
from ansible-role-nginx-config.
Thanks for the quick response.
If I understand your response, you are suggesting I add a location: / to the definition. What I showed above is just a snippet of my play, I already have a proxy for / that fronts a different server, that's why I need the rewrite at nginx level so I can force any request with /publish it to the right server as / (i.e. remove the publish node)
My question really is, using nginx-config role, how do I supply a rewrite statement under a location:? Everything I've tried seems to ignore the rewrite directive, and never makes it into the generated default.conf file.
I'd like the block to be:
location ~ ^/publish {
rewrite ^/publish / break;
proxy_pass http://servername:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr:$remote_port;
proxy_set_header X-Scheme $scheme;
from ansible-role-nginx-config.
Have a look at the link above. It has proper rewrite. A rewrite should have a regex, a replacement and a flags fields. Something like this:
rewrites:
- regex: ^/publish
replacement: /
flag: break
An alternative solution is to let nginx do the replacement:
- location: /publish
# pypi-server
proxy:
pass: "http://{{ dapypi_host }}:8080/"
Note, that I'm not using a '~' in the location configuration and I have added a slash to a pass statement.
Nginx is smart enough to automatically replace the prefix of a location with a URL part from proxy_pass.
You can find out more about it here: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
from ansible-role-nginx-config.
awesome, gotta run out for a bit, I'll give this a test this evening! Thanks for the assist.
Update:
Checked it out, your alternative solution worked, which is simpler than the rewrite (which I still couldn't get to work). I thought I had tried that alternative solution earlier and got an error message, but must have been something else...
Appreciate the assit.
from ansible-role-nginx-config.
Related Issues (20)
- how to insert an if statement in the server stanza HOT 3
- How to omit load_module: modules/ngx_http_js_module.so HOT 3
- mime.types not included in default nginx configuration HOT 4
- Add `include` support in default.conf.j2 template HOT 1
- Templating error HOT 2
- "mappings" from the "map" directive are not applied to a resulting configuration HOT 2
- Role should restart/reload Nginx when SSL certificates change HOT 3
- How to set "global" variables in the HTTP context HOT 5
- Allow nginx.conf.j2 to create gzip settings HOT 2
- Nested location HOT 2
- Question - QUIC config HOT 5
- Enforcing numeric types breaks certain templating patterns. HOT 3
- http2 directive uses enable but http3 uses enabled
- Variables for gzip_static HOT 1
- Logrotate does not format correctly HOT 2
- add map inside stream HOT 3
- Validate configuration HOT 3
- Role version 0.7.1 is not published to the ansible-galaxy repo HOT 1
- set_real_ip_from (ngx_http_realip_module) should be a list HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ansible-role-nginx-config.