adit
adit

Reputation: 33654

configuring nginx server_name if you don't have any domain name pointing to it

I have an ubuntu machine which has an ip address tied to it, and I have a site that i want to configure in my virtual host. the issue is what should I put in my server_name if I don't have any domain pointing to it? essentially I wanted such that when i enter my ip address 2xx.xxx.xxx.xxx then it goes to this site. Here's my current config

server {
        listen          80;
        server_name     dev.somesite.com;
        client_max_body_size 25M;
        access_log      /var/log/nginx/dev.somesite.com.access_log;
        error_log       /var/log/nginx/dev.somesite.com.error_log warn;
server_name_in_redirect off;
        root            /var/www/somesite-dev/web;
        location / {
                try_files $uri /app_dev.php?$args;
        }
        index           app_dev.php index.php index.html;
        fastcgi_index   index.php;

        location ~ \.php($|/) {
                 set  $script $uri;
                set  $path_info "";

                if ($uri ~ "^(.+\.php)(/.*)") {
                        set  $script     $1;
                        set  $path_info  $2;
                }
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
                include /etc/nginx/fastcgi_params;
                keepalive_timeout 0;
                fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_pass    127.0.0.1:9000;
        }
    }

Upvotes: 1

Views: 6848

Answers (2)

K. Norbert
K. Norbert

Reputation: 10674

Server_name is used for name based virtual hosting, if you don't need that, you can leave it out altogether. It will listen on IP just fine. Keep in mind that this will cause problems if you have more than one server that does not use name based resolution, you will only be able to access one of them. Which one depends on two things:

  1. If you have "listen 80 default" in one of the servers, that server will take precedence
  2. If you don't have the above, the server whose configuration is read first will handle the request

Upvotes: 3

Adam Szabo
Adam Szabo

Reputation: 11412

You should set server_name to e.g. development.local and then add a line to your /etc/hosts file when you make development.local to point to the IP of your server, or localhost.

Upvotes: 3

Related Questions