Git Product home page Git Product logo

Comments (4)

oxpa avatar oxpa commented on August 18, 2024

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.

JavaWiz1 avatar JavaWiz1 commented on August 18, 2024

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.

oxpa avatar oxpa commented on August 18, 2024

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.

JavaWiz1 avatar JavaWiz1 commented on August 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.