Question

Access website only through ip with nginx

Hi, I’m new to DigitalOcean. I just configured my first droplet installing Ubuntu and a LEMP stack. At the moment I don’t have a domain to use and wanted just to do some tests. I followed this guide to create a Server Block: https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-14-04-lts

I changed the root line to this:

root /var/www/bbb15.it/html;

and the server_name to my ip.

Nginx is working, but if I try to access the website using ip_address/bbb15.it it doesn’t work.

What can it be? How can I debut the issue?

Thanks

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hey,

I just came accross an issue. Doesn’t matter if its a local setup or one with a domain name.

When you create a symbolic frpom sites-available to sites-enabled you have to use the whole path to each location.

e.g. you can’t

cd /etc/nginx/sites-available/
ln -s monitor ../sites-enabled/

It has to be:

ln -s  /etc/nginx/sites-available/monitor  /etc/nginx/sites-enabled/

Well, a simple fix would be to use the following code in the configuration:

server { server_name localhost; location / { root /var/www/bbb15.it/html; } }

The code above will serve all requests who don’t have a specific block.

The Server Blocks are for setting up virtual hosts. This will allow nginx to serve different web pages for different domain names that all point to the same server allowing multiple domain names and web pages to be served from the same single droplet.

You don’t have multiple domain names or even one domain name, so you had no need to go and change the server_name inside your server block you should have left it alone.

Because you don’t have a domain name your only way of accessing the web pages on your server through a browser on the internet is by entering your servers IP into the address bar. The default server block is what handles these requests.

The default server block means the default web site that will be served when a HTTP request is made to the server by a user that doesn’t specify any other pre-defined vhosts/domain names that exists within your server blocks.

So the default server block will handle and process requests made to the server that are made by entering a raw IP address just like you have to because you don’t have any domain names.

You can’t use bbb15.it as your server name because it isn’t a registered domain name and has no public DNS records pointing to your server. You’re not going to be able to enter bbb15.it into your address bar in a browser and expect your server to serve it because there’s no DNS for it and it doesn’t exist on the public internet.

You COULD access your website through http://bbb15.it (which is how you have configured it currently) ONLY if you was browsing locally from within your servers network, you won’t be able to access that from outside your servers network.

You should have just left your default server block as it was and changed the document root to /var/www/bbb15.it/html and then you could access your web site through your servers IP.

You said you wanted to access it like this http://ip_address/bbb15.it in which case you then need to enter /var/www/bbb15.it/html from your shell and mkdir bbb15.ir and place your web pages inside that folder.

I think you should go back to the basics and have a read up on basic networking as this is very basic stuff. I would suggest going to google and have a read up on the difference between the “intranet and the Internet” this should give you an overview and basic understanding of what I am talking about.

Best of luck