大网数据广告活动
服务器运维问答

How to get nixos configuration.nix to configure nginx?

· 52CE 我爱测

In my configuration.nix, it says services.nginx.enable=true; services.nginx.httpConfig="a"; (I tried a normal file and empty string and neither worked) upon running nixos-rebuild switch , it says that the server was started, but …

问题原文

原帖链接 · nixos · CC BY-SA 3.0

In my configuration.nix, it says

services.nginx.enable=true;
services.nginx.httpConfig="a";

(I tried a normal file and empty string and neither worked)

upon running nixos-rebuild switch, it says that the server was started, but curl localhost connection refuses.

When I run nginx from the command line, it responds could not open error log file: open() "/nix/store/HASHHERE-nginx-1.8.1/logs/error.log failed", read only filesystem.

I looked at the conf file there /nix/store/HASHHERE-nginx-1.8.1/conf/nginx.conf and it's the same as the default! ('diff nginx.conf nginx.conf.default' returns a blank line).

Why doesn't services.nginx.httpConfig change the config file?

已采纳解答

原帖链接 · brocking · CC BY-SA 3.0

It does change the config file, but the config file doesn't get written into the nginx package. Instead it gets written to a new file in a new location.

It confused me a bit at first as well. I found it helpful to make sense of it by remembering that the nix store reflects the purity of the nix functional language - when you change something the original copy should remain the same, instead a new copy is created combined with whatever changes (it's this property that supports instant rollbacks). The same goes for your nginx config - the package is never touched, instead a new config file is created.

As Rok says you can quickly check where the location of the config file is with systemd status. You can also read through the config section for the nginx module to see how the whole thing is implemented. In that case you will see that your nginx.httpConfig text gets written to a configFile in /nix/store/HASHHERE-nginx.conf. That file then gets passed directly to your nginx binary via its -c option. So the nginx systemd unit execStart command is like ${pkgs.nginx}/bin/nginx -c ${configFile}..

PS that is also why your curl returns a connection refused - cos your nginx configuration is just 'a'! The default server is sitting in the nginx package but completely unreferenced (exactly the same thing happened to me).

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-05-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。