Multiple Domains at the Same IP...?

So I've been managing a nice fastcgi setup for a single domain for awhile now and I'd like to expand this to two domains, one of which will host a wiki. I own both domains already and have been using separate services (pythonanywhere+linode) for them and am ready to consolidate and get a bit more serious.

Here is my current config…

lighttpd.conf:

#include "conf.d/cgi.conf"
include "conf.d/fastcgi.conf"

server.modules = (
        "mod_access",
        "mod_fastcgi",
        "mod_alias",
        "mod_rewrite",
        "mod_accesslog",
        "mod_compress",
        "mod_redirect"
)

server.port = 80
server.username = "http"
server.groupname = "http"
server.errorlog = "/var/log/lighttpd/error.log"

server.document-root = "/srv/http/site1.com/"

$HTTP["host"] == "site2.com" {
        server.document-root = "/srv/http/site2.com/"
}

dir-listing.activate = "disable"
index-file.names = ( )
#ssl.engine = "enable"
#ssl.pemfile = "/etc/lighttpd/certs/www.example.com.pem"
mimetype.assign = (
        ".html" => "text/html",
        ".txt" => "text/plain",
        ".css" => "text/css",
        ".js" => "application/x-javascript",
        ".jpg" => "image/jpeg",
        ".jpeg" => "image/jpeg",
        ".gif" => "image/gif",
        ".png" => "image/png",
        ".mng" => "video/x-mng",
        ".svg" => "image/svg+xml",
        "" => "application/octet-stream"
)
static-file.exclude-extensions = ( ".fcgi", ".php", ".rb", "~", ".inc", ".py" )
fastcgi.debug = 1

fastcgi.conf

$HTTP["host"] == "(^|\.)site1\.com$" {
        fastcgi.server = ( "/site1.py" => ((
                "socket" => "/tmp/fastcgi2.socket",
                "bin-path" => "/srv/http/site1.com/site1.py",
                "max-procs" => 1,
                "bin-environment" => (
                        "REAL_SCRIPT_NAME" => ""
                ),
                        "check-local" => "disable"
                )),
                ".php" => (
                        "localhost" => (
                                "host" => "127.0.0.1",
                                "port" => 1026,
                                "bin-path" => "/usr/bin/php-cgi",
                                "broken-scriptfilename" => "enable"
                        )
                )
        )

        url.rewrite-once = (
                "/static/(.*)$" => "/static/$1",
                "^/wikiroot/wiki/upload/(.+)" => "/wiki/upload/$1",
                "^/wikiroot/$" => "/w/index.php",
                "^/wikiroot/wiki/([^?]*)(?:\?(.*))?" => "/w/index.php?title=$1&$2",
                "^/(.*)$" => "/site1.py/$1",
        )
}

$HTTP["host"] == "site2.com" {
        fastcgi.server = ( "/site2.py" => ((
                        "socket" => "/tmp/fastcgi.socket",
                        "bin-path" => "/srv/http/site2.com/site2.py",
                        "max-procs" => 1,
                        "bin-environment" => (
                                "REAL_SCRIPT_NAME" => ""
                        ),
                        "check-local" => "disable"
                ))
        )

        url.rewrite-once = (
                "^/static/(.*)$" => "/static/$1",
                "^/(.*)$" => "/site2.py/$1",
        )

}

/etc/hosts

 <ipaddress>site1.com       myhostname
 <ipv6address>site1.com       myhostname
 <ipaddress>site2.com   myhostname
 <ipv6address>site2.com   myhostname
127.0.0.1       localhost.localdomain   localhost
#::1            localhost.localdomain   localhost</ipv6address></ipaddress></ipv6address></ipaddress> 

DNS Records

I am currently sending @ and www to an a record of <ipaddress>for both site1 and site2 on enom.</ipaddress> 

Currently, fastcgi/lighttpd isn't printing out any syntax errors or anything and site2 works like a charm, buit site1 does not for some reason and gives a 404.

edit: Sorry for this, but I just solved it myself (isn't that always the way of these things? You post the question after hours of working on it, then you solve it within minutes).

I changed the conditional for site1 in fastcgi.conf to…

$HTTP["host"] =~ "^(www\.)?site1.com" {

And it worked like a dream.

0 Replies

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct