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

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a domain and an "alternative" of I'm trying to direct traffic from to using a simple server declaration in nginx as follows:

server {
    listen 80;
    rewrite ^/(.*)$1 permanent;

I'm not 100% sure if this is the right rule, but I've got another vhost on the server, this isn't where the problem is, but it's necessary to understand the issue I'm having.

server {
    listen      8745;
    server_name localhost;
    <other stuff goes here>

Hitting <my server IP>:8745 will go to that vhost, that works as intended. However I've got another vhost like this:

server {
    listen      8746;
    server_name localhost;
    <other stuff goes here>

But all of my requests to <my server IP>:8746 hit I'm... baffled, I don't really grok nginx, so any help would be appreciated as to why this is happening. I mentioned that rule in the beginning because I'm thinking it has something to do with this. If additional information is needed I can supply it.

share|improve this question
If the rewrite block were to be commented out do requests to localhost:8746 then load the correct vhost? Most likely the answer is yes but we should be sure no additional configuration issues are present. My first instinct is that Nginx is somehow defaulting to the block due to the 8746 block not being read/processed. Is it properly symlinked into a sites-enabled dir (if you use that sort of setup)? – CarpeNoctem Feb 16 '10 at 2:52
It's working properly, but I've noticed something interesting. The 301 redirect has a header of X-Powered-By for PHP, which is good, because 8746 is the only vhost running PHP. So it's hitting the vhost properly, but still going to the other domain... I'm baffled by it, I think it's something to do with Wordpress rerouting requests to port 80, I'm looking into that now. – Zack Feb 16 '10 at 21:17
Aha! That was the problem. Wordpress has an option for 'site_url' in the 'wordpress_options' table of it's database. It was set to <the domain>.com, I set it to <the domain>.com:8746 and it worked fine. – Zack Feb 16 '10 at 21:24
Zack, please post an answer to your question (bottom of this page) and then accept it as the answer to the question so it gets closed :) – pauska Feb 16 '10 at 21:44
It's posted below, however I'm waiting on it to let me accept it ("You can accept your own answer in 11 hours."). – Zack Feb 17 '10 at 13:09
up vote 1 down vote accepted

It turns out this isn't an nginx issue. I probably should've noted that <my server IP>:8746 runs a Wordpress installation; Wordpress has an option set (in the wp_options table, the row has option_id of 2 for me and option_name of siteurl) to <some domain>.com, I changed that to <some domain>.com:8746 and it worked fine.

share|improve this answer

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.