Lighttpd: Difference between revisions

From Alpine Linux
No edit summary
 
(19 intermediate revisions by 8 users not shown)
Line 1: Line 1:
[http://www.lighttpd.net/ lighttpd] is a simple, standards-compliant, secure, and flexible web server.


==General information==
Its name is a portmanteau of "light" and "httpd": [https://www.lighttpd.net/ lighttpd] is a simple, standards-compliant, secure, and flexible web server.


* Configuration file: /etc/lighttpd/lighttpd.conf
'''lighttpd is a powerful server, made long ago to handle upwards of 10,000 connections in parallel on one server'''. It was used in wikipedia server a long time ago and also some google services.
* Standard directory for files: /var/www/localhost/htdocs/


== Installation ==
{{Note|As for minimal sites and quick-start purposes, it is recommended due to its easy configuration process and excellent performance without much configuration. Check https://w3techs.com/technologies/details/ws-lighttpd and note that it is used in high traffic and important sites like postgresql.org}}
lighttpd is available in the Alpine Linux repositories. To install, simple launch the command below:


{{Cmd|apk add lighttpd}}
== General information ==


== Configuration ==
{| class="wikitable"
If you just want to server simple HTML pages lighttpd can be used out-of-box. No further configuration needed.
|-
! Feature/Artifact !! Value/Name !! Observations
|-
| Main package name || lighttpd || <code><nowiki>apk add lighttpd</nowiki></code>
|-
| Manpages and DOCs packages || lighttpd-doc || <code><nowiki>apk add lighttpd-doc</nowiki></code>
|-
| Configuration file || {{Path|/etc/lighttpd/lighttpd.conf}} || A vanilla default configuration
|-
| Html place for system pages || {{Path|/var/www/localhost/htdocs/}} || Each web server in alpine has own path for that
|-
| Dynamic files (cache, extra) || {{Path|/var/lib/lighttpd/}} || Created dynamically, each server in alpine has own path for that
|-
| Log files (error, access, etc) || {{Path|/var/log/lighttpd/}} || Each web server in alpine has own path for that
|-
| User running the webserver || lighttpd || Others Linux used "www-data" alpine has as a group
|-
| Group to common to webserver || www-data || Used to share things amont others daemons or services, like redis or apache files
|-
| Programed on || C and lua || Main engine code in C, modules and config in Lua variants
|}


== Controlling Lighttpd ==
==== Important Limitations ====


=== Start lighttpd ===
Some common hosting panels do not handle {{Pkg|lighttpd}} configuration management.
{{Cmd|/etc/init.d/lighttpd start}}
 
No HTTP/3 support.
 
As we read previously.. main purpose was handle several request on one server, so are focused on high load.
 
As main front end web server are perfect and it's '''recommended as reverse proxy server for {{Pkg|apache2}} or {{Pkg|nginx}}'''.
 
== Install Lighttpd ==
The installation works out of the box for static pages. After installing you can see webserver in action by putting any file inside the {{Path|/var/www/localhost/htdocs/}} directory.
 
Per user web files are supported by default in {{Path|/home/<user>/public_html}} directory by default if we enable it (process are described below in further section "Lighttpd configuration".
 
{{Pkg|lighttpd}} is available in the Alpine Linux repositories. To install, simple launch the commands below:
{{cmd|apk add lighttpd
rc-update add lighttpd default
rc-service lighttpd restart}}
 
== Testing Lighttpd ==
 
This section is assuming that lighttpd is running. If you now launch a web browser from a remote system and point it to your web server, you will see a page that says "404 - Not Found". Well, at the moment there is no content available but the server is up and running.
 
Let's add a simple test page to get rid of the "404 - Not Found page":
 
{{Cmd|echo '<!DOCTYPE html><html><head><title>✔️</title><meta charset&#61;"utf-8"></head><body>Lighttpd is running!</body></html>' > /var/www/localhost/htdocs/index.html}}
 
'''For testing open a browser and go to {{ic|<nowiki>http://127.0.0.1/</nowiki>}} and you should see "Lighttpd is running!"'''. Note the example usage of "127.0.0.1" indicating that the lighttpd server and the web browser are running on the same machine.
 
If you are using alpine remotely, '''open a browser on your client machine, and go to {{ic|http://<webserveripaddres>/}}. The "webserveripaddres" is the IP address of your lighttpd server machine.'''
 
== Lighttpd Configuration ==
 
'''If you just want to serve simple HTML pages lighttpd can be used out-of-box. No further configuration needed.'''
 
For production purposes the [[Production LAMP system: Lighttpd + PHP + MySQL]] wiki page will explain in details all the needs, there's the [[Production Lets Encrypt: dehydrated]] wiki page with futher information to use HTTPS and lets encrypt certificates.
 
Due to the minimalism of alpine linux, '''unfortunately the lighttpd packaging only provided vanilla configurations not close to alpine or easy admin maintenance''', see the [[Production LAMP system: Lighttpd + PHP + MySQL]] wiki page to goin in deep about configuring lighttpd web server.
 
==== Controlling Lighttpd ====
 
'''''Start lighttpd''''': After the installation {{Pkg|lighttpd}} is not running. As we made in first section was started already but if you want to start {{Pkg|lighttpd}} manually use:
 
{{Cmd|rc-service lighttpd start}}


You will get a feedback about the status.
You will get a feedback about the status.
Line 26: Line 84:
</pre>
</pre>


=== Stop lighttpd ===
'''''Stop lighttpd''''': If you want to stop the web server use ''stop'' in the same way of previous command:
If you want to stop the web server use ''stop''.


{{Cmd|/etc/init.d/lighttpd stop}}
{{Cmd|rc-service lighttpd stop}}


=== Restart lighttpd ===
'''''Restart lighttpd''''': After changing the configuration file lighttpd needs to be restarted.
After changing the configuration file lighttpd needs to be restarted.


{{Cmd|/etc/init.d/lighttpd restart}}
{{Cmd|rc-service lighttpd restart}}


=== Runlevel ===
'''''Proper Runlevel''''': By default no services are added to start process, sysadmin must know what we want and what will services do, also other main reason are due in dockers there's no runlevels per se and Alpine linux are mostly used in dockers containers. You must added the servide only to the default runlevel, not to boot, because need networking activated
Normally you want to start the web server when the system is launching. This is done by adding lighttpd to the needed runlevel.


{{Cmd|rc-update add lighttpd default}}
{{Cmd|rc-update add lighttpd default}}


== Testing Lighttpd ==
= See Also =
This section is assuming that lighttpd is running. If you now launch a web browser from a remote system and point it to your web server, you will see a page that says "404 - Not Found". Well, at the moment there is no content available but the server is up and running.
 
Let's add a simple test page to get rid of the "404 - Not Found page".
 
{{Cmd|echo "Lighttpd is running..." > /var/www/localhost/htdocs/index.html}}
 
Now you will get the new "test page" if you reload.


== Advanced configurations ==
In production web, LAMP means '''L'''inux + '''A'''pache + '''M'''ysql + '''P'''hp installed and integrated, but today the "A" of apache are more used as Nginx or Lighttpd, and the "M" of MySQL are more used as Mariadb, the LAMP focused documents are:


* [[Lighttp Https access|Securing Lighttpd with https]]
* [[Setting_Up_Lighttpd_with_PHP|Setting Up Lighttpd with PHP]]  
* [[Setting_Up_Lighttpd_with_PHP|Setting Up Lighttpd with PHP]]  
* [[Setting_Up_Lighttpd_With_FastCGI|Setting Up Lighttpd With FastCGI]]
* [[Lighttpd Advanced security]]  


[[Category:Networking]]
[[Category:Web_Server]]
[[Category:Development]]

Latest revision as of 10:12, 16 July 2024

Its name is a portmanteau of "light" and "httpd": lighttpd is a simple, standards-compliant, secure, and flexible web server.

lighttpd is a powerful server, made long ago to handle upwards of 10,000 connections in parallel on one server. It was used in wikipedia server a long time ago and also some google services.

Note: As for minimal sites and quick-start purposes, it is recommended due to its easy configuration process and excellent performance without much configuration. Check https://w3techs.com/technologies/details/ws-lighttpd and note that it is used in high traffic and important sites like postgresql.org

General information

Feature/Artifact Value/Name Observations
Main package name lighttpd apk add lighttpd
Manpages and DOCs packages lighttpd-doc apk add lighttpd-doc
Configuration file /etc/lighttpd/lighttpd.conf A vanilla default configuration
Html place for system pages /var/www/localhost/htdocs/ Each web server in alpine has own path for that
Dynamic files (cache, extra) /var/lib/lighttpd/ Created dynamically, each server in alpine has own path for that
Log files (error, access, etc) /var/log/lighttpd/ Each web server in alpine has own path for that
User running the webserver lighttpd Others Linux used "www-data" alpine has as a group
Group to common to webserver www-data Used to share things amont others daemons or services, like redis or apache files
Programed on C and lua Main engine code in C, modules and config in Lua variants

Important Limitations

Some common hosting panels do not handle lighttpd configuration management.

No HTTP/3 support.

As we read previously.. main purpose was handle several request on one server, so are focused on high load.

As main front end web server are perfect and it's recommended as reverse proxy server for apache2 or nginx.

Install Lighttpd

The installation works out of the box for static pages. After installing you can see webserver in action by putting any file inside the /var/www/localhost/htdocs/ directory.

Per user web files are supported by default in /home/<user>/public_html directory by default if we enable it (process are described below in further section "Lighttpd configuration".

lighttpd is available in the Alpine Linux repositories. To install, simple launch the commands below:

apk add lighttpd rc-update add lighttpd default rc-service lighttpd restart

Testing Lighttpd

This section is assuming that lighttpd is running. If you now launch a web browser from a remote system and point it to your web server, you will see a page that says "404 - Not Found". Well, at the moment there is no content available but the server is up and running.

Let's add a simple test page to get rid of the "404 - Not Found page":

echo '<!DOCTYPE html><html><head><title>✔️</title><meta charset="utf-8"></head><body>Lighttpd is running!</body></html>' > /var/www/localhost/htdocs/index.html

For testing open a browser and go to http://127.0.0.1/ and you should see "Lighttpd is running!". Note the example usage of "127.0.0.1" indicating that the lighttpd server and the web browser are running on the same machine.

If you are using alpine remotely, open a browser on your client machine, and go to http://<webserveripaddres>/. The "webserveripaddres" is the IP address of your lighttpd server machine.

Lighttpd Configuration

If you just want to serve simple HTML pages lighttpd can be used out-of-box. No further configuration needed.

For production purposes the Production LAMP system: Lighttpd + PHP + MySQL wiki page will explain in details all the needs, there's the Production Lets Encrypt: dehydrated wiki page with futher information to use HTTPS and lets encrypt certificates.

Due to the minimalism of alpine linux, unfortunately the lighttpd packaging only provided vanilla configurations not close to alpine or easy admin maintenance, see the Production LAMP system: Lighttpd + PHP + MySQL wiki page to goin in deep about configuring lighttpd web server.

Controlling Lighttpd

Start lighttpd: After the installation lighttpd is not running. As we made in first section was started already but if you want to start lighttpd manually use:

rc-service lighttpd start

You will get a feedback about the status.

 * Caching service dependencies                                 [ ok ]
 * Starting lighttpd...                                         [ ok ]

Stop lighttpd: If you want to stop the web server use stop in the same way of previous command:

rc-service lighttpd stop

Restart lighttpd: After changing the configuration file lighttpd needs to be restarted.

rc-service lighttpd restart

Proper Runlevel: By default no services are added to start process, sysadmin must know what we want and what will services do, also other main reason are due in dockers there's no runlevels per se and Alpine linux are mostly used in dockers containers. You must added the servide only to the default runlevel, not to boot, because need networking activated

rc-update add lighttpd default

See Also

In production web, LAMP means Linux + Apache + Mysql + Php installed and integrated, but today the "A" of apache are more used as Nginx or Lighttpd, and the "M" of MySQL are more used as Mariadb, the LAMP focused documents are: