I have my site on the IP 1.2.3.4
On my domain provider I have both onesite.com and anothersite.com pointing to 1.2.3.4
With Nginx, I have two sites configured:
server {
listen 1.2.3.4:80;
server_name www.oneserver.com;
rewrite ^(.*) http://onserver.com$1 permanent;
}
server {
listen 1.2.3.4:80;
server_name onserver.com;
location / {
fastcgi_pass 127.0.0.1:8878;
[..]
And:
server {
listen 1.2.3.4:80;
server_name myapp.anotherserver.com;
location / {
fastcgi_pass unix:/tmp/myapp.sock;
[..]
When I access myapp.anotherserver.com I get redirected to oneserver.com
Any help?
As
user186340
pointed out, your configuration snippet looks good and accessingmyapp.anotherserver.com
in port80
should be served in the 3rd block you provided. If it does not work as you describe, it might be because it is not loaded.nginx -t
to validate your configurationHUP
signal to the nginx master process to spot any error message popping upnginx -T
to dump the loaded configuration to standard outputIf all the following was OK, you probably modified the showed configuration compared to the one you effectively use.
The problem is Nginx chooses the default server and serves that to any request without a server explicitly defined. My workaround is to define a default server that does nothing.