restricting access only through domains on nginx on virtual hosts
I have finished setting up nginx for virtual hosting, this is how my config files look like
server {
listen 80;
server_name domain.com;
access_log /home/domain.com/prod_webapp/logs/access.domain.com.log;
error_log /home/domain.com/prod_webapp/logs/error.domain.com.log;
location /static {
root /home/domain.com/prod_webapp/mocorner/ph/;
}
location / {
try_files $uri @uwsgi;
}
location @uwsgi {
include uwsgi_params;
uwsgi_pass unix:/tmp/domain_uwsgi.sock;
}}
on the same machine, I have domain1.com and domain2.com, each when i access I get its content which is great. My problem is that when i try to access the user using the IP address i get one of the sites in the virtual hosts too..
Although i disabled the default (removed the symbolic link) from sites-enabled folder but still not solved it for me.
any suggestions?
Solution 1:
You may handle such requests by creating the default webserver configuration like this:
server {
listen 80 default;
server_name localhost;
}
This option is called default_server
since 0.8.21. See documentation for details.
Solution 2:
Just insert a catch all block and restrict access to every other request to your IP.
server { listen 80 default_server; server_name _; return 444; }