# Rewrite and proxy\_pass at the same time in nginx

**URL:** <https://www.ruby-forum.com/t/rewrite-and-proxy-pass-at-the-same-time-in-nginx/237545>\
**Category:** NGINX\
**Created:** [November 18, 2013, 9:55pm UTC](https://www.ruby-forum.com/t/rewrite-and-proxy-pass-at-the-same-time-in-nginx/237545 "2013-11-18T21:55:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [November 18, 2013, 9:55pm UTC](https://www.ruby-forum.com/t/rewrite-and-proxy-pass-at-the-same-time-in-nginx/237545/1 "2013-11-18T21:55:49Z")

</div>

HI guys. I am trying to make something to work in nginx but I have no  
luck.  
I posted in StackOverflow, and no answer.  
I wish any of you can help me. I paste the SO question here as well:

I am using nginx and I need a proxy to redirect some service. From my  
application, I should be able to do a POST, for example, to this URL:  
[http://localhost:8776/specialService/aserverthatlistens.com/serviceToCall](http://localhost:8776/specialService/aserverthatlistens.com/serviceToCall).  
And I need to rewrite it like this:  
[https://aserverthatlistens.com/serviceToCall](https://aserverthatlistens.com/serviceToCall) (notice that this URL is  
HTTPS,  
not HTTP).

I know I can use rewrite but I don’t know how to use proxy\_pass also,  
because the url of the proxy\_pass should be what I rewrote…

Notice that I cannot know in advance what is the final url  
([aserverthatlistens.com](http://aserverthatlistens.com) in this example), so I always need to get it  
form  
the URL. I could send it as parameter if that help instead of being part  
of  
the URL.

So far my server configuration looks like this:

server  
{  
listen 8776;  
server\_name localhost;

access\_log /var/log/nginx/tunnel.log;  
error\_log /var/log/nginx/error.log info;

location ~ ^/someService(/.\*)$ {  
proxy\_pass https://$1;

}

}

Posted at Nginx Forum:

> **[rewrite and proxy\_pass at the same time in nginx](https://forum.nginx.org/read.php?2,244782,244782#msg-244782)**
>
> HI guys. I am trying to make something to work in nginx but I have no luck. I posted in StackOverflow, and no answer. I wish any of you can help me. I paste the SO question here as well: I am using nginx and I need a proxy to redirect some service....

---

<div class="post-metadata">

**Author:** ![marianopeck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecd19e/32.png) [@marianopeck](https://www.ruby-forum.com/u/marianopeck)\
**Post date:** [November 18, 2013, 11:56pm UTC](https://www.ruby-forum.com/t/rewrite-and-proxy-pass-at-the-same-time-in-nginx/237545/2 "2013-11-18T23:56:12Z")

</div>

On Mon, Nov 18, 2013 at 03:55:08PM -0500, marianopeck wrote:

Hi there,

> server  
> {  
> location ~ ^/someService(/.\*)$ {  
> proxy\_pass https://$1;  
> }  
> }

What does the error log say?

What does the error log say when you change proxy\_pass to have 2 slashes  
and not 3?

## f

Francis D. removed\_email\_address@domain.invalid
