0

Nginx config:

server {
        listen 443 ssl;
        server_name xyx.com;


    location /name/ {
        rewrite    /name/([^/]+) /users?name=$1 break;
        proxy_pass http://127.0.0.1:80/;
}
} 

The above link works well if its just location / but with any other path like above location /name/ it fails.

We want the location path to be part of the url when requested.

All xyz.com/name url (and dependent) should proxy/redirect the users to http://127.0.0.1:80/name

Tried proxy_pass http://127.0.0.1$request_uri and other few stuff including rewrite and it didn't work.

Any suggestions appreciated - thanks.

1 Answer 1

0
server {
    ......
    ...... stuff

    location / {
        proxy_pass http://Client;
        proxy_buffering off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Port $server_port;

        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;

    }

    location /identity/ {
            proxy_pass http://Identity/;

            proxy_buffering off;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Port $server_port;

            fastcgi_buffers 16 16k;
            fastcgi_buffer_size 32k;

    }

}

upstream Client{
        zone Client 64k;
        server localhost:5001;
}



upstream Identity{

        zone Identity 64k;
        server localhost:9001;
}

example.com ===> my client project
example.com/identity ===> my identity project

NOTE: some times you may have to define the original url in your project middleware pipeline. in my case i configure identity server and it generates urls. i have to add below in my middleware pipeline to understood it that your origin base url is example.com/identity/ so the urls must generate base on this base url.(.net core)

app.Use(async (ctx, next) =>
{
    ctx.Request.Scheme = "https";
    ctx.Request.Host = new HostString("example.com/identity/");
    
    await next();
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.