Reputation: 71
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?
Upvotes: 7
Views: 23330
Reputation: 45
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.
Upvotes: 2
Reputation: 6027
Your dev workstation's /etc/hosts
file is readed only when you open a browser (or want to reach the network) from your dev workstation. If you reach the network from your mobile the dev workstation's /etc/hosts
will be ignored.
If you want to reach 192.168.2.11
as site1.dev
from your mobile or tablet too you should create an /etc/hosts
-entry on each device (same as on your workstation).
Other possibility is to use your router when your router supports local DNS function.
Or a complicated solution (a very ugly hack) is to install a DNS server to your workstation and sets the router's DNS to your workstation's IP.
Upvotes: 6