0

I installed nginx on a debian server. I have three servers (virtual hosts):

  • default (/etc/nginx/sites-enabled/0-default)
  • mydomain.com (/etc/nginx/sites-enabled/1-mydomain)
  • booking.mydomain.com (/etc/nginx/sites-enabled/2-booking)

When I access to the server with its domain names, I get the right websites. But when I access to the server with its IP address, it's the booking website that is returned.

This booking website is on Symfony, here is the content of the sites-enabled/2-booking file:

server {
server_name booking.mydomain.com;
root /var/www/booking/web;

location / {
    # try to serve file directly, fallback to app.php
    try_files $uri /app.php$is_args$args;
    limit_req zone=one burst=20;
}

location ~ ^/(app|app_dev|config)\.php(/|$) {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param HTTPS off;
}

error_log /var/log/nginx/booking_error.log;
access_log /var/log/nginx/booking_access.log;

}

I want my server to return the /var/www/index.php file when it is accessed from its IP address, do you have an idea of what to do ?

Nidal
  • 187
  • 4
  • 11
maxime
  • 140
  • 2
  • 6

1 Answers1

2

To set explicitly the default server you can add default_server to listen directive in /etc/nginx/sites-enabled/0-default. So that parameter becomes.

listen *:80 default_server;

Snippet from How nginx processes a request

In this configuration nginx tests only the request’s header field "Host" to determine which server the request should be routed to. If its value does not match any server name, or the request does not contain this header field at all, then nginx will route the request to the default server for this port. In the configuration above, the default server is the first one — which is nginx’s standard default behaviour. It can also be set explicitly which server should be default, with the default_server parameter in the listen directive

masegaloeh
  • 18,236
  • 10
  • 57
  • 106