openwrt / openwrt/packages

nginx refuses to start if server _lan is disabled or not defined

Open
#11,533 28 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stale
Dominant language
Makefile
Stars
4.6k
Forks
4k
Avg merge
3d 12h
Merged PRs (30d)
134

Description

@heil @Ansuel @peter-stadler

Commit 2401fd6db5e582d1b1442e4832222a3fee50937a introduced sweeping changes to /etc/init.d/nginx and to the way Nginx configuration files have to be written.

  1. /etc/init.d/nginx now forces users to put Nginx configuration files into /etc/nginx/conf.d/. If you have a customized version of /etc/nginx/nginx.conf that uses the "include" directive to read configuration files from some other location, like the commonly-used /etc/nginx/sites or /etc/nginx/sites-enabled, you are out of luck. The new version of /etc/init.d/nginx hardcodes the location of the configuration files /etc/nginx/conf.d/ by way of using nginx-util.

  2. /etc/init.d/nginx now uses nginx-util to automatically create a default configuration for Nginx in /etc/nginx/conf.d/_lan.conf which loads "listen" and "default_server" directives from /var/lib/nginx/lan_ssl.listen and /var/lib/nginx/lan_ssl.listen.default. This default configuration makes Nginx listen on ports 80 and 443 (in case of nginx-ssl) on all IP addresses associated with the LAN adapter. Now if someone wants to change Nginx configuration so that there is no default server and there are only named virtual servers responding to specific domain names, one has to disable the "_lan" server. The updated OpenWrt Nginx Wiki page now says that "We can disable single configuration parts by giving them another extension, e.g., by adding .disabled." Renaming _lan.conf to _lan.conf.disabled and adding domain-specific configuration files into /etc/nginx/conf.d/ causes Nginx failure to start:

root@OpenWrt:~# /etc/init.d/nginx start
init_lan notice: no server named _lan

To be clear, by mandating "_lan" server which uses directives from /var/lib/nginx/lan_ssl.listen and /var/lib/nginx/lan_ssl.listen.default it is no longer possible to configure Nginx in OpenWrt to drop requests without the "Host" header field, which is precisely the case when Nginx receives a "rogue" https request with no SNI specified.

Since /etc/init.d/nginx now relies on nginx-util to create a default configuration, nginx package now has an additional dependency: nginx-util. For users like me who already have a well-working Nginx configuration, nginx-util provides zero benefit while consuming ~130KB of space on an OpenWrt device.

While an attempt to provide a reasonable default configuration for a package in OpenWrt is laudable, in this particular case it has created more problems than it has solved. First, Nginx already comes with reasonably good default configuration. Second, it is completely unacceptable to force a particular configuration on users where it is not necessary. Mandating the "_lan" server and mandating the default servers listening on all IP addresses associated with the LAN interface are all unacceptable.

As a minimum:

  • users must not be forced to place all domain-specific configuration files into /etc/nginx/conf.d/,
  • "_lan" server must not be mandatory,
  • /var/lib/nginx/lan_ssl.listen must not be mandatory, and
  • /var/lib/nginx/lan_ssl.listen.default must not be mandatory.

As a maximum:

  • nginx should not depend on nginx-util. Nginx-util must be an optional package for those users who want nginx-util to offer a default configuration. Those users who are happy with the default Nginx configuration should not be forced to install nginx-util.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading /etc/init.d/nginx and nginx-util/src/nginx-util.hpp, then review the linked Nginx wiki guidance and the configuration behavior described in the issue. Done means nginx can start without a defined or enabled _lan server, without requiring the lan_ssl.listen files, and without forcing nginx-util on users who do not need its defaults.

Written by the indexing model from the issue text.

Assessment

Tech stack
nginx
Domain
web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.