2

Using Debian 9, the behaviour of systemd is the following:

  • At boot-time nginx does not seems to read /etc/hosts and failed to start
  • After boot, when the command systemctl start nginx it is working properly

Note: the file /etc/hosts is correct and remains untouched during all the tests.

After searching for a while, I tried to start systemd-resolved before nginx. There is no impact.

Oct 13 11:14:01 server-dev systemd-resolved[466]: Positive Trust Anchors:
Oct 13 11:14:01 server-dev systemd-resolved[466]: . IN DS 19036 8 2 49aac11d7b6f6446702e54a1607371607a1a41855200fd2ce1cdde32f24e8fb5
Oct 13 11:14:01 server-dev systemd-resolved[466]: . IN DS 20326 8 2 e06d44b80b8f1d39a95c0b0d7c65d08458e880409bbc683457104237c7f8ec8d
Oct 13 11:14:01 server-dev systemd-resolved[466]: Negative trust anchors: 10.in-addr.arpa 16.172.in-addr.arpa 17.172.in-addr.arpa 18.172.in-addr.arpa 19.172.in-addr.arpa 20.172.in-addr.arpa 21.172.in-addr.arpa 22.172.in-addr.arpa 23.172
Oct 13 11:14:01 server-dev systemd-resolved[466]: Using system hostname 'server-dev'.
Oct 13 11:14:01 server-dev systemd-resolved[466]: Switching to system DNS server 192.168.1.1.
Oct 13 11:14:01 server-dev shorewall[465]: Compiling using Shorewall 5.0.15.6...
Oct 13 11:14:01 server-dev systemd[1]: Started Network Name Resolution.
Oct 13 11:14:01 server-dev systemd[1]: Starting A high performance web server and a reverse proxy server...
Oct 13 11:14:01 server-dev systemd[1]: Reached target Multi-User System.
Oct 13 11:14:01 server-dev systemd[1]: Reached target Graphical Interface.
Oct 13 11:14:01 server-dev systemd[1]: Starting Update UTMP about System Runlevel Changes...
Oct 13 11:14:01 server-dev systemd[1]: Started Update UTMP about System Runlevel Changes.
Oct 13 11:14:01 server-dev nginx[502]: nginx: [emerg] host not found in upstream "server-dev.com" in /etc/nginx/sites-enabled/default:33
Oct 13 11:14:01 server-dev nginx[502]: nginx: configuration file /etc/nginx/nginx.conf test failed
Oct 13 11:14:01 server-dev systemd[1]: nginx.service: Control process exited, code=exited status=1
Oct 13 11:14:01 server-dev systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Oct 13 11:14:01 server-dev systemd[1]: nginx.service: Unit entered failed state.
Oct 13 11:14:01 server-dev systemd[1]: nginx.service: Failed with result 'exit-code'.

Any suggestion?

0

I found a working solution, it is linked to nginx proxy configuration. I am not clear about the impacts, feel free to comment or propose a better solution.

  1. Install dnsmasq

  2. Add a domain name resolver in nginx configuration

server {
# redirect DNS requests to local dnsmasq
resolver 127.0.0.1;

# without these 2 lines, nginx does not resolve name correctly
set $mt_proxy_from "http://server-dev.com:8000";
set $mt_proxy_dest "https://server-dev.com";
[...]
location / {
# Proxy configuration
proxy_pass $mt_proxy_from;
proxy_read_timeout 90;
proxy_redirect $mt_proxy_from $mt_proxy_dest;
}}

I don't like this solution because it seems not efficient:

  • Install dnsmasq and add a resolver to nginx sounds OK
  • Add NGINX dynamic variables to resolve the names dynamically (not clear when?) seems weird because the local addresses are fixed

Question: is there any way to do something clean?

  • Configure the IP addresses in /etc/hosts
  • Make NGINX resolve the names according /etc/hosts at systemd boot time?

Sources:
https://stackoverflow.com/questions/8305015/when-using-proxy-pass-can-etc-hosts-be-used-to-resolve-domain-names-instead-of
https://www.jethrocarr.com/2013/11/02/nginx-reverse-proxies-and-dns-resolution/

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.