0

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

server {
    listen 80;
    server_name some-example.com;
    rewrite ^/(.*) http://example.com/$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 example.com. 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.

5
  • 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 exmaple.com 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)? Feb 16, 2010 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, 2010 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, 2010 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, 2010 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, 2010 at 13:09

1 Answer 1

1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .