For the purpose of running a webserver on my NixOS installation, I have included the following in my configuration.nix. (Note that I have very little experience with setting up servers and have not found exact definitions of all of the parameters included below.)

 services.httpd = {
    enable = true;
    adminAddr = "localhost";

    extraModules = [ "http2" ];

    virtualHosts = 
        hostName = "localhost";
        documentRoot = "/home/edmund/docroot";
        enableUserDir = true;
        servedDirs = [ { urlPath = "/www"; dir = "/www"; } ];
        serverAliases = [ "localhost" ];
        enableSSL = false;

However when I try to access the default index.html page through http://localhost on a Firefox browser, the message which comes up is 'Access forbidden! Error 403' (with some additional descriptive text).

Is this because HTTPD_ROOT and the DocumentRoot listed in the httpd.conf file both seem to point to a directory inside /nix/store, which has tightly locked permissions? (Rather than the document root which I specified.)

How can I configure this server to display a page?



"Is this because HTTPD_ROOT and the DocumentRoot listed in the httpd.conf file both seem to point to a directory inside /nix/store,"

Possibly. It may also be that there is actually no file by the name of index.html in any of the so-called "DocumentRoot"

httpd.conf takes precedence. So any file outside must be included from within that file, to change the snazas within httpd.conf.

Any mor difinative answer will require your providing that so-called "some additional descriptive text" you mentioned. That additional text is generally a description of why there was that failure.

Lastly; why would you attempt to contradict what you already have defined in httpd.conf? It the current context, it makes no sense.


  • Thanks for your quick response. Here is the full text from the browser: 'Access forbidden! You don't have permission to access the requested object. It is either read-protected or not readable by the server. If you think this is a server error, please contact the webmaster. Error 403 localhost Apache/2.4.39'
    – edmund
    Jun 15 '19 at 7:11
  • I have confirmed that there is an index.html in the DocumentRoot pointed to by the httpd.conf which I find in the HTTPD_ROOT location. I had inferred that because the HTTPD_ROOT is inside /nix/store, and because the contents of the HTTPD_ROOT are read-only (even for root), that Nix must be setting up the httpd.conf based on configuration.nix. This is why I thought that the documentRoot which I specified in the configuration.nix might show up in httpd.conf.
    – edmund
    Jun 15 '19 at 7:17
  • Just to be clear: When (as root) I try to use chmod on the httpd.conf, it states that it is a read-only file system. I cannot modify it directly.
    – edmund
    Jun 15 '19 at 7:19
  • That's exactly the error message I had anticipated. The path your web client is directed does not contain an index.html file. So your web server throws that message. It's just fine if the (web) folder is read only. In fact that's best. Your only problem is the path you're directing web clients does NOT contain an index file.
    – somebody
    Jun 15 '19 at 7:42

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.