Linux web server files

How to quickly set up http file sharing on GNU/Linux

If you have a good internet connexion it could be useful to be able to share files with friends via a home made solution.

We will see here how to set up a web server in order to easily share files via a http protocol on GNU/Linux.

The goal here is to do it quickly with minimal configuration.

We will use lighttpd wich is an open-source web server optimized for speed-critical environments while remaining standards-compliant, secure and flexible.

Small CPU load and low memory footprint, everything I’m looking for.

Installing lighttpd

Edit configuration file

  • Edit /etc/lighttpd/lighttpd.conf, and add this line :
  • Create upload directory :
  • Create example file :
  • Reload lighttpd service :

Connect to the web server

GNU/Linux | Lighttpd Index of

  • From your web browser connect to your newly web server (http://IP_ADDRESS/upload). From the Index of page you should see your file :

How to secure?

We have a our brand new http server but if we make it accessible from the internet (that’s what we wanted right?), everyone can potentially connect to it.

We will see here, how we can improve security.

Firewall rules

We can use the netfilter/iptables or nftables firewall to restrict access and thus allow only certain ip addresses.

Netfilter/iptables rules

root@host:~# iptables -A INPUT -p tcp —dport 80 -m state -s ALLOWED_IP —state NEW,ESTABLISHED,RELATED -j ACCEPT root@host:~# iptables -A INPUT -p tcp —dport 80 -m state —state NEW,ESTABLISHED,RELATED -j DROP

nftables rules

root@host:~# nft add rule ip filter INPUT tcp dport 80 ip saddr ALLOWED_IP ct state new,established counter accept root@host:~# nft add rule ip filter INPUT tcp dport 80 ct state new,established counter drop

Читайте также:  Планшет huawei mediapad linux

Add authentication

We can also add a user/password prompt window to prevent unwanted users.

GNU/Linux | Lighttpd auth window

  • Edit /etc/lighttpd/lighttpd.conf, and add this lines :

server.modules = ( «mod_indexfile», «mod_access», «mod_alias», «mod_redirect», «mod_auth», «mod_authn_file» ) auth.backend = «plain» auth.backend.plain.userfile = «/etc/lighttpd/lighttpd-plain.user» auth.require = ( «/» => ( «method» => «basic», «realm» => «Auth», «require» => «valid-user» ) )

  • Add new user login:password :

root@host:~# echo «agent007:secret» > /etc/lighttpd/lighttpd-plain.user

  • Restart lighttpd service :

root@host:~# systemctl restart lighttpd.service

  • The next time someone tries to log in an authentication request will appear :

Add https support

  • Create a self signed certificate :
  • Set rights :
  • Edit /etc/lighttpd/lighttpd.conf, and add this lines :
  • Restart lighttpd service :

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Источник

Share Files Using Lightweight Http Servers in Linux

Lightweight server applications in Linux can be used to quickly share files between two or more devices. These web server applications are not suitable for advanced web applications that require tighter security, authentication and performance. However, they are perfectly fine if you want to use them to temporarily share files locally or remotely between multiple devices. This article will list some of these static HTTP server applications. So let’s jump in.

SimpleHTTPServer

Simple HTTP server is a built-in python module that can be used to launch a lightweight server suitable for running basic web applications and lightweight file server. As it is a built-in module, it comes pre-installed on almost all Linux distributions having Python installed by default.

Simple HTTP server serves all the files located in the folder it is run from. Run the following commands in succession to launch a simple HTTP server in the “Downloads” folder located in your home directory (commands below are for Python 3 only).

To run the server on a different port, run the following command instead (change port number according to your requirements):

You will see following terminal output on successful launch of the server:

If you click on the URL mentioned in the terminal output shown above, you will be able to see a basic file browser layout in the web browser (also on http://localhost:8000/):

Читайте также:  Split file in parts linux

To share files with a different device, you have to use a URL in the “http://ip_address:8000/” format. To find IP address of of your computer where simple HTTP server is running, run the command below:

You will get some output like this:

Enter the IP address obtained above in the URL. The correct URL to access the file server now would be: “http://192.168.0.107:8000/”. You can open this URL in any web browser on any device to download the listed files. Below is a screenshot of this URL opened on an Android device:

To stop the server anytime, press while the terminal window is in focus.

HTTP-Server (Node.js)

Http-server is a Node.js module that allows you to run a simple, easy to use and configurable web server. You can use the http-server module to share files from any folder on your system.

To install Node.js on Ubuntu, run the command below:

To install http-server module, run the command below:

To run the http-server from “Downloads” folder in your home directory, run the following two commands in succession:

On successful launch of http-server, you will see some output like this:

You can now use the second URL listed in the output above to open the file browser in a web browser.

To stop the server anytime, press while the terminal window is in focus.

Twistd

Twistd is a simple web server that comes with the “Twisted” python module. It can be used to launch a server that uses http or ftp protocol for sharing files. To install twisted in Ubuntu, run the command below:

To run the twistd from “Downloads” folder in your home directory, run the following two commands in succession:

On successful launch of web server, you will get some output in the terminal like this:

You can now use a URL in the “http://ip_address:8080/” format. To see IP address of your system, run the command below:

Читайте также:  Нужны ли знания linux

You will get some output like this:

Enter the IP address obtained above in the URL. The correct URL to access the file server now would be: “http://192.168.0.107:8080/”. You can open this URL in any web browser on any device to download the listed files. Below is a screenshot of this URL opened in Firefox web browser on Ubuntu:

To stop the server anytime, press while the terminal window is in focus.

Httpd (Ruby)

Httpd is a lightweight server that comes with the default Ruby package on most Linux distributions. In terms of functionality, it is on par with Python’s simple HTTP server.

To install Ruby on Ubuntu, run the command below:

To run the Ruby httpd from “Downloads” folder in your home directory, run the following two commands in succession:

On successful launch of web server, you will get some output in the terminal like this:

You can now use a URL in the “http://ip_address:8000/” format. To see IP address of your system, run the command below:

You will get some output like this:

Enter the IP address obtained above in the URL. The correct URL to access the file server now would be: “http://192.168.0.107:8080/”. You can open this URL in any web browser on any device to download the listed files. Below is a screenshot of this URL opened in Firefox web browser on Ubuntu:

To stop the server anytime, press while the terminal window is in focus.

Conclusion

These are a few lightweight web server applications that are easy to use and can be used to share files publicly. If you want to share files over a network with higher security and authentication standards, these applications may not be suitable and avoid using them in production.

About the author

Nitesh Kumar

I am a freelancer software developer and content writer who loves Linux, open source software and the free software community.

Источник

Оцените статью
Adblock
detector