Answer the question
In order to leave comments, you need to log in
Nginx: Why does it redirect from the main one domain to another?
there is domain1.com on the server, it hangs on nginx + php5-fpm
Added another ip to the server,
set up dns for the second domain, resolves correctly,
registered the config in /sites-available/domain2.com,
linked with /sites-enabled
why _ domain2.com/index.html works, but _ domain2.com redirects to
_ domain1.com is a bastard. I can’t understand
, well, yes, rebutyl, but the configs are standard, like, there’s nothing special to change there
server {
listen 80;
root /var/www/user1/data/www/domain1.com;
index index.html index.htm index.php;
server_name domain1.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
if ($http_host ~ "^115\.1\.1\.1"){ rewrite ^(.*)$ http://domain1.com$1 redirect; }
}
server {
listen 80;
root /var/www/user2/data/www/domain2.com;
index index.html index.htm index.php;
server_name domain2.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
if ($http_host ~ "^115\.2\.2\.2"){ rewrite ^(.*)$ http://domain2.com$1 redirect; }
}
Answer the question
In order to leave comments, you need to log in
Why do you need this garden with a check through if and redirects?
If constructs in nginx configs are not recommended. They can slow down the system and you can usually do without them.
If I understood correctly, then you have two domains and each should respond only to its own IP address. Now you have both configs configured so that they listen on any ip address.
And you need to do this:
server {
listen 115.1.1.1:80;
server_name domain1.com;
access_log /var/www/logs/nginx-domain1.access.log combined;
error_log /var/www/logs/nginx-domain1.error.log;
root /var/www/user1/data/www/domain1.com;
index index.html;
location / {
try_files ...;
}
}
server {
listen 115.2.2.2:80;
server_name domain2.com;
access_log /var/www/logs/nginx-domain2.access.log combined;
error_log /var/www/logs/nginx-domain2.error.log;
root /var/www/user2/data/www/domain2.com;
index index.html;
location / {
try_files ...;
}
}
error_log /var/log/nginx/error.log debug;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question