Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have set 4 domains up using Nginx etc. and have an html folder structured as follows:

html/site1/
html/site2/
html/site3/
html/site4/

The problem is when I go to 123.456.789.012 I get the default Nginx page and my domains are actually at 123.456.789.012/site1/ etc. This makes sense to me, I know why it's doing it, all sites are in sub folders from the root.

Basically I want 123.456.789.012 to redirect to 123.456.789.012/site1/ but without the /site1/ attached. Is this possible without moving my files of site1 to the root?

Does it even matter leaving it as is? I can't imagine anyone wanting to browse my site via IP.

share|improve this question
    
"I want 123.456.789.012 to redirect to 123.456.789.012/site1/ but without the /site1/ attached" What? I can't understand this. –  leonbloy Apr 21 '13 at 1:38
    
If there's no need to browse via IP then don't listen on your IP, only respond when someone comes in on domain.com –  Drew Khoury Apr 21 '13 at 4:40
add comment

2 Answers

up vote 1 down vote accepted

Just add default_server parameter to directive listen for corresponding server {} section of nginx.conf

For example,

server {
    listen 80 default_server;
    server_name site1.domain.com;

    location / {
        root /path/to/html/site1;
    }
}

http://nginx.org/en/docs/http/ngx_http_core_module.html#listen

The default_server parameter, if present, will cause the server to become the default server for the specified address:port pair. If none of the directives have the default_server parameter then the first server with the address:port pair will be the default server for this pair.

share|improve this answer
    
Thanks. This solution made the most sense to me out of the two. Turns out I already had the default parameter and only had to add /site1 to the root path. Not sure why I didn't think to try that. –  Xenor Apr 21 '13 at 9:42
    
Well this actually killed my PHPMyAdmin, which is also in html/ Probably because my config is wrong. I added some code to try fix that but it just loaded the PHPMyAdmin index without images or CSS. Edit: I fixed that by moving the PHPMyAdmin shortcut to the /site1/ directory. –  Xenor Apr 21 '13 at 15:25
    
You did not mention anything about PHPMyAdmin, located in html, not any of siteN folders :) Glad to hear, anyway, that your issue is solved. –  cadmi Apr 22 '13 at 9:49
add comment

Sounds like you're looking for the root directive:

server {
    # things;
    location / {
        root /path/to/site1/;
        # things;
    }
}

Given how the question is worded, however, this might not be what you want. It would pay to read the documentation: http://wiki.nginx.org/HttpCoreModule#root

It would be helpful if you posted your nginx.conf also.

share|improve this answer
add comment

Your Answer

 
discard

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.