Accessing NGINX virtual host in local network

Viewed 17055

I would like to access a virtual host on my dev workstation (Arch Linux) from mobile or tablet connected in the same network.

My nginx.conf virtual host spec looks like this:

http {

include mime.types;
default_type application/octet-stream;

sendfile on;
keepalive_timeout 65;
client_max_body_size 16M;

# Domain site1.dev
server {
    server_name site1.dev;
    listen 80;
    root /path/to/dir;

    location / {
        root /path/to/dir;
        index index.php;
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /path/to/dir/$fastcgi_script_name;
        include fastcgi_params;
    }
}

}

My /etc/hosts file contains:

127.0.0.1    localhost localhost.localdomain site1.dev
192.168.1.11 site1.dev

This works on localhost, but I can't reach site1.dev from phone or tablet connected in the same network. It works only using IP address 192.168.1.11 Is there some way how to make it work using site1.dev name?

2 Answers

You can just replace the server_name site1.dev, by the IP address , if you are developing some website or some backend to do your tests , otherwise you need to configure DNS

I just give it a try and it will be like :

server_name 192.168.1.11;

and you don't need to put is in the hosts file.

Related