Project

General

Profile

How do I use a Domain url instead of IP address and port to access website hosted on local server?

Added by midnight_milloir 23 days ago

So, I have a web server hosted on a linux machine, only accessible on the local network. Normally I could view the website from any machine connected to the network by typing in the IP address and port number in a browser. I'd like to switch to using a domain name instead of an IP address to access my website (e.g. "caseloader.com" instead of "x.x.x.x:8080"). I have two websites hosted on my machine, and with the second website being hosted on a different port. I'd like to get it to where I can access them by using subdomains. Here is my lighttpd file.

server.modules   += ( "mod_fastcgi" )
server.modules += ( "mod_rewrite" )
fastcgi.debug = 1
debug.log-request-handling = "enable"
debug.log-file-not-found = "enable"
server.document-root = "/var/www/"
$SERVER["socket"] == ":8080" {
server.username = "lighttpd"
server.groupname = "supervisor"
server.document-root = "/var/www/"
server.port = 8080
mimetype.assign = (
".html" => "text/html"
)
url.rewrite-once = (
"^(/static($|/.*))$" => "$1",
"^(/.*)$" => "/application.fcgi$1"
)
$HTTP["host"] =~ "^(www\.)?caseloader.com$" {
server.document-root = "/var/www/"
server.chroot = "/var/www/CaseLoader_Fl"
fastcgi.server = ( "application.fcgi" =>
(( "socket" => "/tmp/fastcgi.socket",
"bin-path" => "/home/knf/.virtualenvs/caseloader-webapp/bin/python/var/www/application.fcgi",
"max-procs" => 1,
"bin-environment" => (
"REAL_SCRIPT_NAME" => ""
),
"check-local" => "disable"
))
)
}
}

Before, I had this line:

$HTTP["host"] =~ ":8080$" {

instead of

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

and that allowed me to connect to my website by typing in the IP address in my browser like this: http://x.x.x.x:8080. Now, however, using caseloader.com does not redirect me to my website.

I'd like to first understand what I'm doing wrong, and second, learn how to achieve what I'm trying to do. Again, the end goal is to allow for all the computers on my local network to access my website through a domain name instead of an IP address. I don't mind if they have to type in the port after the domain like "caseloader.com:8080", but I would rather have that than an IP address.

Thanks.


Replies (11)

RE: [Solved] How do I use a Domain url instead of IP address and port to access website hosted on local server? - Added by gstrauss 23 days ago

Inside $SERVER["socket"] == ":8080", you defined a host. Given http://caseloder.com:8080/ your browser will send Host: caseloader.com:8080, so your match should be
$HTTP["host"] =~ "^(www\.)?caseloader.com:8080$"

RE: [Solved] How do I use a Domain url instead of IP address and port to access website hosted on local server? - Added by midnight_milloir 19 days ago

This did not work for me. I replaced this line

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

with this line

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

but when typing http://caseloader.com:8080/ into my my browser I am met with the error "This site can't be reached".

RE: How do I use a Domain url instead of IP address and port to access website hosted on local server? - Added by gstrauss 19 days ago

Well, you misspelled "caseloader" above. Please also make sure that you have properly restarted lighttpd after making configuration changes.

RE: [Solved] How do I use a Domain url instead of IP address and port to access website hosted on local server? - Added by midnight_milloir 16 days ago

I apologize for the spelling error. I have just corrected it. However, the spelling error was not the issue, as it still does not work.

Define properly restarting lighttpd. I'm pretty sure you just have to run the command

sudo lighttpd restart

correct? If so then my issue lies elsewhere.

RE: How do I use a Domain url instead of IP address and port to access website hosted on local server? - Added by gstrauss 16 days ago

Your first problem is that you seems to have underspecified (and continue to underspecify) your issue, what you're trying to do, and why.

See DebugVariables You probably want to debug.log-request-header = "enable" and review what is being sent by the browser and how it might match your config regexes.

RE: How do I use a Domain url instead of IP address and port to access website hosted on local server? - Added by midnight_milloir 13 days ago

What I'm trying to do is I want to forward the url www.caseloader.com, using lighttpd, to all the computers connected to my local network so that people can type the url into their respective browsers and connect to my website. I was easily able to forward the IP address and port of the computer running the website, but I don't want to have to give out the IP address of that computer every time it changes. It would be much easier to just have people type in a url and have it connect to my website.

Lighttpd should be able to make this happen. I've read the documentation of lighttpd over and over again, and it seems I should just change the host to make it match to caseloader.com, but it isn't working. I don't think I know enough about lighttpd or networking to understand why it isn't working.

I will try debugging and let you know the results.

<Update>
So looking at the logs, there are no new logs or errors created when I try typing caseloader.com in the browser. The error in the browser just says "Site can't be reached".

However, when typing the IP address and port into the browser, it just downloads my fcgi script.

RE: How do I use a Domain url instead of IP address and port to access website hosted on local server? - Added by gstrauss 13 days ago

It's pretty clear you haven't read much documentation. Not sure where you got the idea that lighttpd will look anywhere in the URL-path for "application.fcgi". It won't.

    if $HTTP["url"] !~ "^/static(/|$)" {
        fastcgi.server = ( "" =>
         (( "socket" => "/tmp/fastcgi.socket",
            "bin-path" => "/home/knf/.virtualenvs/caseloader-webapp/bin/python/var/www/application.fcgi",
            "max-procs" => 1,
           "bin-environment" => (
             "REAL_SCRIPT_NAME" => "" 
           ),
           "check-local" => "disable" 
         ))
         )
    }

RE: How do I use a Domain url instead of IP address and port to access website hosted on local server? - Added by midnight_milloir 12 days ago

This doesn't help my problem, I could already access my website using the IP and port using this line

$HTTP["host"] =~ ":8080$" {

RE: How do I use a Domain url instead of IP address and port to access website hosted on local server? - Added by stbuehler 12 days ago

midnight_milloir wrote:

What I'm trying to do is I want to forward the url www.caseloader.com, using lighttpd, to all the computers connected to my local network so that people can type the url into their respective browsers and connect to my website. I was easily able to forward the IP address and port of the computer running the website, but I don't want to have to give out the IP address of that computer every time it changes. It would be much easier to just have people type in a url and have it connect to my website.

I can't tell what you're actually trying to achieve from this description. So...

If you enter http://caseloader.com:8080/ into your browser, it will lookup the IP address(es) for caseloader.com using DNS (or your local hosts file), and then it will try to connect to TCP port 8080 on one of those addresses.

You say that entering IP address and port allows you to connect, but it doesn't connect with the name, which sounds to me like you didn't quite get what DNS does for you. And this wouldn't be a lighttpd issue. (Just saying: from the outside we can't connect to caseloader.com:8080 either).

The second part of the problem seems to be that you want to run some FastCGI application, but didn't actuallly configure it, so it just downloads your script.

gstrauss: Please don't post examples using /tmp/ as location for the FastCGI-socket; not a good choice with security in mind. Usually something like /var/run/lighttpd/ is a good place (should only be writeable by lighttpd) for FastCGI applications spawned by lighttpd.

RE: How do I use a Domain url instead of IP address and port to access website hosted on local server? - Added by midnight_milloir 12 days ago

So, currently I have a lighttpd config file with this line

$HTTP["host"] =~ ":8080$" {

in place of this line

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

and it works fine. I can type my computer's IP and port in the address bar of a browser on another computer and view my website. I thought that having

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

would allow me to type in www.caseloader.com:8080 and would connect to my computers IP the same way typing the IP and port in a browser would, but it doesn't. I suspected that this might require me to go in and change my DNS settings as well, but I wanted to post on here to see if there was a way to configure lighttpd to allow for this to work the same way typing the IP and port does.

I don't want my website to be public. I only want computers on the LAN connection to be able to connect with my website, and this is working how it should. Also, the FastCGI application runs how it should. The reason why it was downloading my script was because when I had this line

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

typing the IP and port would match with the $SOCKET statement, but it wouldn't reach the second statement that actually ran my FastCGI application. I'm already aware of why that was happening, I was just trying to communicate the symptoms of my issue.

So is there in fact no way of using lighttpd to allow typing in a URL to connect to my computer without changing either the DNS configurations or the local hosts file (on each computer respectively)?

RE: How do I use a Domain url instead of IP address and port to access website hosted on local server? - Added by stbuehler 12 days ago

midnight_milloir wrote:

[...]
So is there in fact no way of using lighttpd to allow typing in a URL to connect to my computer without changing either the DNS configurations or the local hosts file (on each computer respectively)?

You need some way to resolve the name to an IP address - maybe MDNS (the ".local" zone) is an option for you.

    (1-11/11)