Skip to content

nginx: update to 1.17.6 and use custom /etc/nginx/nginx.conf [RFC]#9859

Closed
peter-stadler wants to merge 1 commit into
openwrt:masterfrom
peter-stadler:nginx
Closed

nginx: update to 1.17.6 and use custom /etc/nginx/nginx.conf [RFC]#9859
peter-stadler wants to merge 1 commit into
openwrt:masterfrom
peter-stadler:nginx

Conversation

@peter-stadler
Copy link
Copy Markdown
Contributor

@peter-stadler peter-stadler commented Aug 29, 2019

Maintainer: Thomas Heil heil@terminal-consulting.de and Ansuel Smith ansuelsmth@gmail.com
Compile tested: MIPS 74K, Asus RT-N16, master snapshot
Run tested: MIPS 74K, Asus RT-N16, master snapshot, let it serve luci-ssl-nginx

Description:
Replace the standard config file containing commented examples with a minimal /etc/nginx/nginx.conf file that will load all /etc/nginx/conf.d/*.conf files. So other packages can install their server { … } parts for nginx in that directory instead of replacing or modifying the main nginx.conf file.

This PR includes also the corresponding changes for luci on nginx (nginx-mod-luci and nginx-mod-luci-ssl). I made also another PR for nginx-luci and nginx-ssl-luci that collect their files from packages …

In the official packages there is just one other app that uses nginx at this time: ariang. See my other PR for changing its nginx part accordingly.

Edit: I did update this PR to follow the changes in the meantime. I would update the other PR for nginx-luci and nginx-ssl-luci later if you think it is a good idea to extract the luci files from the nginx and uwsgi-cgi packages.

Edit2: Changed the documentation and included files/README.sh in the package for creating the documentations’s configuration part with the variables from the sources.
Furthermore, changed the default logging behavior: access_log off; error_log stderr; that is forwarded by the init to logd.

@peter-stadler peter-stadler changed the title nginx: enable /etc/nginx/conf.d directory for server parts of other packages nginx: enable /etc/nginx/conf.d directory for server parts of other packages [RFC] Aug 29, 2019
@peter-stadler peter-stadler marked this pull request as ready for review October 28, 2019 08:32
@peter-stadler
Copy link
Copy Markdown
Contributor Author

I did update this PR to follow the changes in the meantime. The luci PR still refers to the old version, I could update it afterwards.

Comment thread net/nginx/Makefile
Comment thread net/nginx/files/10_nginx-conf_set_worker_processes Outdated
@feckert
Copy link
Copy Markdown
Member

feckert commented Oct 29, 2019

@Ansuel looks ok now ready to merge?

@peter-stadler
Copy link
Copy Markdown
Contributor Author

peter-stadler commented Oct 29, 2019

We are discussing, how other sites should be included on behalf of the example of ariang: #9860 Would wait for that …

@peter-stadler
Copy link
Copy Markdown
Contributor Author

peter-stadler commented Oct 31, 2019

This is one proposal:

The file /var/nginx_lan.listen keeps the IP addresses of the LAN and is used in the server parts of nginx in /etc/nginx/conf.d/*.conf.

The server part /etc/nginx/conf.d/lan.conf pulls in this file and all location parts in /etc/nginx/conf.d/*.locations. So, different sites can install their location parts there and they will be available on LAN.

The locations can also be used in other /etc/nginx/conf.d/*.conf. server parts for making selected sites available on WAN under different domains, i.e. server_name.

The /var/nginx_listen_lan.conf file is (re-)created if nginx starts or the LAN interface changes.

@Ansuel
Copy link
Copy Markdown
Member

Ansuel commented Nov 5, 2019

Looks good... last thing, a readme in the etc nginx config would be good

Last thing how to handle service that should run on https and should be redirected from http to https ?

@peter-stadler
Copy link
Copy Markdown
Contributor Author

Thank you. You are right I will write a config for https and then a readme ...

@peter-stadler
Copy link
Copy Markdown
Contributor Author

peter-stadler commented Nov 8, 2019

Took me some time for adding ssl to the init, now it should work quite automagically:

  1. Everytime nginx-ssl starts, we check if the LAN has already a valid ssl certificate in
    /etc/nginx/conf.d/_lan.{crt,key}
  2. If there is no valid certificate, we try to create a self-signed one (that needs px5g or openssl-util to be installed, too)
  3. When there exists a certificate, we add corresponding ssl_certificate* directives to the configuration file
    /etc/nginx/conf.d/_lan.conf
    if needed and if it looks “normal”, i.e., it has a server_name _; part.
  4. When there is a valid certificate for the LAN, we activate ssl by listen $IP:443 ssl; directives in
    /var/nginx_lan.listen
    and it becomes available by the default redirect from listen *:80; in
    /etc/nginx/conf.d/_redirect2ssl.conf
  5. If cron is available (not inactive), we use it to check the certificate for validity once a year and renew it if there are only 13 months of the more than 3 years life time left.

The prime points 2, 3 and 5 can be used for other domains, too: Create a
/etc/nginx/conf.d/www.example.com.conf
with a corresponding server_name www.example.com; part and call
service nginx create_selfsigned_certificate_if_needed www.example.com
I did not test it for other domains, though.

I am glad if you can run it and I am open for any comments. Meanwhile, I would do some more tests and then write a documentation ...

@peter-stadler
Copy link
Copy Markdown
Contributor Author

Did some tests and cleaned it up.

@peter-stadler
Copy link
Copy Markdown
Contributor Author

Made some minor improvements and fixes. The docu is WIP.

@peter-stadler peter-stadler changed the title nginx: enable /etc/nginx/conf.d directory for server parts of other packages [RFC] nginx: update to 1.17.6 and use custom /etc/nginx/nginx.conf [RFC] Nov 19, 2019
@peter-stadler
Copy link
Copy Markdown
Contributor Author

peter-stadler commented Nov 27, 2019

The documentation should be quite ready, made some changes for logging errors to syslog and set access_log off by default. What do you think?
Edit: Made some little changes/fixes and adapted nginx-mod-luci*.

@peter-stadler peter-stadler force-pushed the nginx branch 2 times, most recently from ae7ab02 to 48bebd4 Compare November 28, 2019 11:37
@peter-stadler peter-stadler force-pushed the nginx branch 6 times, most recently from fd6e780 to 55a7ed6 Compare November 28, 2019 14:28
Instead of the default nginx.conf file this file is a small variant without examples that enables the /etc/nginx/conf.d/ directory.
It will pull in all configuration files from the conf.d directory.
So, other packages can add their server parts in the conf.d directory without modifying the main nginx.conf file.
Changed default logging behavior: error_log stderr; access_log off;
See also the updated documentation at: https://openwrt.org/docs/guide-user/services/webserver/nginx

See also: openwrt#9860

Signed-off-by: Peter Stadler <peter.stadler@student.uibk.ac.at>
@hnyman
Copy link
Copy Markdown
Contributor

hnyman commented Jan 4, 2020

Is this PR still relevant?

@peter-stadler
Copy link
Copy Markdown
Contributor Author

peter-stadler commented Jan 7, 2020

I created a tool (now) that does the main work, see #10960. When that is aproved, I will create another PR that superseeds this one here.

@neheb
Copy link
Copy Markdown
Contributor

neheb commented Jan 17, 2020

This must be rebased. Or closed.

@peter-stadler
Copy link
Copy Markdown
Contributor Author

As the nginx-util is merged, I will make a new PR on Monday.

@peter-stadler
Copy link
Copy Markdown
Contributor Author

(Draft PR at #11081)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants