Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am new to nginx, I have rewrite directives to redirect hostnames to other hostnames. I want to preserve the URI in the request to the redirect so for example goes to and so on.

At the moment I just have this...

server {
    listen 80;
    rewrite /;

I want something more complicated that preserves the request and forwards it.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Adapted from the example on

server {
    listen 80;
    return $scheme://$request_uri;

($scheme expands to http or https depending on connection type)

Have a look at the documentation at before asking further questions on this.

share|improve this answer
Won't I need $request_uri on the end to preserve the specific request? –  John Tate Jul 14 '13 at 16:48
@JohnTate Oops, you are correct. I was not paying attention here. –  Lekensteyn Jul 14 '13 at 19:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.