2

When I open some .html file on my Windows 8.1 (for example this file C:\Users\me\sbox\foo\client\index.html) in a browser (the url is this: file:///C:/Users/me/sbox/foo/client/index.html), the browser parses the file and I can see it the same way like I visited a web page. No running web-server needed, because it is only html markup file.

I want to do the same on my Ubuntu (Amazon Linux actually). I want to type an IP address of my Ubuntu into a browser and get /var/www/index.html. I mean public IP, that is: http://123.12.12.12/ or http://123.12.12.12/index.html and get the page in a browser.

Is it possible? How to achieve it? Do I really need any web servers running? I just want to open an .html file, not .php or whatever, no parser needed.

As I understand, I need to:

  1. open :80 port

  2. set some config so that all public inbound http:80 requests should go to /var/www folder.

Am I right? How to do it?

  • To use your public IP address (i.e. your IP address on the WAN) you'll probably need some kind of DNS service also, to take care of the possible disconnections / reconnections of your server from your ISP (unless you have a static IP). Do you just want to access the file locally or over the internet? – kos Jul 15 '15 at 5:58
  • @kos, Yes, over the internet. I'm connecting my Linux from Windows 8.1 using PuTTY. But want to access index.html on Linux over the internet. – Green Jul 15 '15 at 6:02
  • Definitely need a web server running. – Ben Winding Jul 15 '15 at 7:19
  • @DKBose: look at the answers first (excellent) and then edit out the off-topic part before VTC. (done already) – Fabby Jul 15 '15 at 18:07
  • Green: some excellent answers... Don't forget to accept ☑ the best! ;-) – Fabby Jul 15 '15 at 18:10
6

If you want a quick and dirty one-line command, use python SimpleHTTPServer

python -m SimpleHTTPServer

How to use it example for your case:

$ cd /var/www
$ python -m SimpleHTTPServer

Thats it! This will be serving current directory /var/www. Default port is 8000, so your website will be accessible from http://ip-address:8000 or at your local machine http://localhost:8000

To access other files not named index.html, use their name http://ip-address:8000/other-name.html, if there is no index.html, you will see a directory listing with all the files in your folder.

To change port, you need to have sudo priviliges:

$ sudo python -m SimpleHTTPServer 80

This command will be serving your directory on port 80, if you have apache2 already installed, you can change this port to 81, so it does not have a port conflict and you will access your website from http://ip-address:81, don't forget to allow these ports in your firewall, to allow port 80 use:

$ sudo ufw allow 80/tcp

No webserver

Another way is not to use any web-server, just install your favorite desktop environment and browser on your server and connect to it with remote desktop of your choice. Then your website will be available from the browser as you are used to at file:///var/www/index.html

  • I've never seen that before. Will use this in the future. Cheers – Ben Winding Jul 15 '15 at 10:15
  • Special thanks for the example with Python. One question: how can I stop SimpleHTTPServer? – Green Jul 15 '15 at 10:47
  • @Green You stop it by simply Ctrl + C as other commands run from command line. – Mike Jul 15 '15 at 11:04
  • Where does SimpleHTTPServer write its logs to? – Green Jul 15 '15 at 14:08
  • 1
    @Mike Sir, your quick and dirty one-line command just saved my life, I wanted to let you know that, thank you so much. – Hans Dec 13 '17 at 5:50
5

Yes, you need a web server. Look at the URL you are requesting. If the first part - the protocol - is "file:", then the browser will do a local search for the file. If the protocol is "http:", the browser will open a network connection on port 80 to the server part of the URL.

Only if you have managed to mount some sort of network share to the Amazon Linux server, you might be able to use the "file:" protocol here. Otherwise you need a web server on the other end, even if you only want the html file transferred, not parsed and executed in the case of .php. Luckily, installing Apache2 does exactly that, and it is not difficult.

1

To access your files through a browser, from another computer, you will need a webserver to manage the requests.

Apache webserver will do exactly this.

Installation

sudo install apache2

Start server

sudo /etc/init.d/apache2 start

Stop server

sudo /etc/init.d/apache2 stop

When the Apache server is running all these URL's point to the same file, try them in your browser.

file:///var/www/html/index.html

localhost/index.html

{you ip address}/index.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.