Please find the below setting which is placed in /etc/nginx/sites-enabled under my site domain name. (mysite.lk)
server {
listen 80;
server_name mysite.lk www.mysite.lk;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass "http://127.0.0.1:8080";
}
}
The application is running on port 8080 and here I'm redirecting all the 80 traffic to 8080. My website only uses mysite.lk and www.mysite.lk domain names.
Hence, I want to restrict/block all other domains (except mysite.lk and www.mysite.lk) which are coming to this server IP. What is the change that I need to do to achieve this?
I tried numerous things such as answers given in the Why is nginx responding to any domain name?, but was getting errors at the nginx startup.
Please help me out! Thanks.
Update
Found the Answer. A catch-all server block should needed in the top of the config before the given config like below. The code block should be like this.
server {
return 403;
}
server {
listen 80;
server_name mysite.lk www.mysite.lk;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass "http://127.0.0.1:8080";
}
}