How to open a file in a browser?

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: or 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?

6

3 Answers

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 or at your local machine

To access other files not named index.html, use their name , 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 , 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

6

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.

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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like