Firefox can't connect to a local site, but Chrome can
Asked Answered
B

10

20

I have a web server running locally that's mapped to project.name.localhost:3011 on a MacOSX box. My /etc/hosts defines:

127.0.0.1 project.name.localhost

I need to browse to this server in Chrome and Firefox. Chrome works great when I visit http://project.name.localhost:3011/. Firefox gives an "Unable to connect" connect error. I can see in my local server's console that no connection attempt was even sent to the server when I try from FF.

This is on FF version 59.0.2 (64-bit). FF has no problem with public internet sites like this one, and google.

I've already tried all of the steps suggested here: https://support.mozilla.org/en-US/kb/firefox-cant-load-websites-other-browsers-can In summary, those steps are:

  • Check proxy settings, verify proxy is turned off
  • Set network.dns.disableIPv6 to true in about:config
  • Set network.dns.disablePrefetch to true in about:config
  • Cleared all history, including cookies and cache

Also tried disabling HSTS as described here: https://support.mozilla.org/en-US/questions/1204380

ping project.name.localhost

works just fine also. There is no local DNS issue.

http://127.0.0.1:3011/ gives me the exact same error as using the hostname. However, I need to access the server via a hostname. It is not and should not be configured to respond on a direct IP.

How can I get FF to hit my local web server via a hostname?

EDIT: Two co-workers experienced what they describe as the same problem when they setup their systems, but they both said "it just went away on its own" after a day or two. My problem has persisted across weeks and reboots.


Console output from request:

GET http://global.appen.localhost:3011/invoice_groups

Request headers (398 B) 
Accept  
text/html,application/xhtml+xm…plication/xml;q=0.9,*/*;q=0.8
Accept-Encoding 
gzip, deflate
Accept-Language 
en-US,en;q=0.5
Cache-Control   
no-cache
Connection  
keep-alive
Host    
global.appen.localhost:3011
Pragma  
no-cache
Upgrade-Insecure-Requests   
1
User-Agent  
Mozilla/5.0 (Macintosh; Intel …) Gecko/20100101 Firefox/59.0

Network Timing:

Blocked:          → 1 ms
DNS resolution:                  → 1 ms
Beagle answered 4/5, 2018 at 22:35 Comment(13)
Hey! Cross-posting the same question on multiple sites is generally discouraged, and I see that you've posted this on SU too: superuser.com/questions/1319868/… Please be patient, and if you want your question to attract more attention, you can put a bounty on it after two daysCouscous
In case your user profile corrupted or misconfigured somehow, did you try to create a new Firefox user profile to test with that?Taxdeductible
This may be a proxy issue. You may have configured a proxy and the localhost would point to the proxy in that case. Please be 100% sure there is no proxy or auto proxy configured in FirefoxLeonardaleonardi
I'm going to go out on a limb and ask if you're using any VPN services like HotSpot Shield? Can you show screenshots of Chrome and Firefox?Incuse
You just got this error now or you are already working with that and the error just pop-up?Arrowworm
@amingilani I have a VPN configured on this system, Tunnelblick. I get the same results in Firefox with the VPN software connected, disconnected, or quit entirely. Is there something else I need to do with the VPN setup? Others: As stated in the question, there is no proxy and proxy is disabled in the browser.Beagle
Please check the firefox developer console. Please share the response headers of the response. Also, try the clean install, support.mozilla.org/en-US/questions/979032. Seems to have worked with some people.Coastal
open developer tools and check the console for errors. if there is none, go to network section and see for network traffic from localhost.Arlenarlena
This is strange. I am not sure if you have tried this 1) Change the port 2) Install a different version of FF. 3) crossbrowsertesting.comMayer
Well, stupid question, but here goes.... Do you have adblocker installed on firefox? And if you do, can you disable it and try again? If that doesn't work do you have something else like NoScript or any javascript addon?Scutage
See this answer #10186883 What Okan Aslankan suggested. "In the Location bar, type about:config and press "Enter" The about:config "This might void your warranty!" warning page may appear. "Click I'll > be careful, I promise!", to continue to the about:config page. In the Search field, type "browser.urlbar.autocomplete.enabled" Double-click the "browser.urlbar.autocomplete.enabled" preference to set its value to false."Uveitis
I've had this problem on every new environment I set up. For other users: If you're on a brand new machine, before changing a bunch of settings, edit your host file like OP did. Keep an entry for localhost, and in addition, add one for your vhost 127.0.0.1 myname.localhostSeraglio
for me setting "network.dns.disableIPv6 : False" fixed it.Proprietary
B
2

Firefox gave special treatment to ".localhost" which seems to have caused to problems. When I change my hosts file from project.name.localhost to project.name.devl it started working.

Beagle answered 9/7, 2018 at 18:51 Comment(0)
A
13

Edit: Not working [seems internate stops working in firefox with this]

in firefox type about:config

search localhost in it and make below flag true

network.dns.native-is-localhost

Edited

Sorry Its Not reliable solution

Arrogate answered 31/1, 2020 at 12:23 Comment(4)
Tks for this unique and simple correct answer I found.Gelderland
This makes any site that isn't localhost stop working.Whitley
3 days lost because of this little variablePartite
I've just updated Firefox in Linux Mint and having issues with the websites on my localhost that use https. Awesome contribution bud!Fley
L
2

You probably just have to clear your FF browser cache. Sometimes you have to clear it all, not just for the site you are working on. Have you done this yet? Old caches can create very mysterious problems like this.

Leverhulme answered 4/5, 2018 at 22:45 Comment(3)
Already tried that - clearing cache was among the steps in the article I mentioned (I'll edit the question to include those steps)Beagle
I figured. But one thing to note is that sometimes you have to clear the whole cache, not just the cache for the individual site. You probably did that, just in case.Leverhulme
just means I now have to log back in to all sites - annoyingLaccolith
B
2

Firefox gave special treatment to ".localhost" which seems to have caused to problems. When I change my hosts file from project.name.localhost to project.name.devl it started working.

Beagle answered 9/7, 2018 at 18:51 Comment(0)
M
2

I had an issue with Firefox, where it opened localhost:1234, but couldn't connect and load any resources from static.localhost:1234.

This only happened on sub-domain with a port specified. Thus, static.localhost worked fine.

Adding

127.0.0.1 static.localhost

to hosts file (located in C:\Windows\System32\drivers\etc) solved the problem for me.

Motorway answered 18/4, 2020 at 9:4 Comment(1)
This worked. In Linux and Mac need to edit the /etc/hosts.Timi
I
1

I would suggest a couple of things:

  • In the hosts file, add the name www.project.name.localhost, in case Firefox is adding www to it. It would look like this:

    127.0.0.1 project.name.localhost www.project.name.localhost

  • Use an HTTP Header analyzer such as Fiddler to monitor the connections Firefox and Chrome are making when you're using http://project.name.localhost:3011/. That will tell you if there's a problem resolving the IP or if there's a difference with the requests made by Chrome.

  • When pinging, use /4 to check the IPv4 and /6 for IPv6 to make sure it's resolving properly.
Isologous answered 14/5, 2018 at 17:3 Comment(0)
L
0

You might also try running from the command line:

nbtstat -R

That will flush your windows name cache.

I don't really think this will solve this though because the name works in one browser, just not FF.

Just to be sure, when you're clearing the FF cache, go to Options -> Privacy & Security. From there you want to clear "Cached Web Content" and "Site Data". You're getting both of those?

If it still won't work, you may have found a FF bug, although that seems highly unlikely. Specifying a host and port number is very standard and it seems highly unlikely that FF could somehow not be able to do that in this case.

You might also break the problem down. What happens when you just call the host without the port number? You might want to make your server serve up a test page on port 80 and see if that part of the call is working. That at least would narrow it down to the port number. Or, perhaps narrow it down to the fact that it's not calling the server correctly.

Leverhulme answered 6/5, 2018 at 17:25 Comment(1)
This is on Mac, not WindowsBeagle
J
0

Try to create another endpoint, like localhost:3011/test, see if works, firefox could check your url and your suffix or prefix might consider incomplete and automatically add some prefixes, in location bar type about:config then Search: fixup and double-click browser.fixup.alternate.enabled so it becomes false. See if that helps.

Juster answered 14/5, 2018 at 13:2 Comment(0)
S
0

I'm using a simple machine name or alias, I solved this issue with this setting:

browser.fixup.dns_first_for_single_words = true

Although the right solution is to use name.localhost instead of just name.

Soothsay answered 14/9, 2021 at 12:44 Comment(0)
F
0

network.dns.disablePrefetch = false

I used this to stop FF from going to https a few days ago.

Formalism answered 30/9, 2023 at 11:22 Comment(0)
D
-1

It is not about your configuration in machine. Firefox adds 'www' prefix when you visit subdomain of localhost and Chrome does not.

Dry answered 14/5, 2018 at 16:16 Comment(6)
No it doesn't. Can you give a citation for this?Incuse
I didn't mean to come across as hostile, but since you're the one making the claim, the burden of proof lies on you to give a quality reference. It also makes your answer more robust.Incuse
We are not at the academy. I've dealt with the issue to gain enough experience on same topic. So I share it which should help to solve problem. If you don't think it is not a good answer, you explain why it is not. I cannot give citation to every single answer I wrote here. It might be Firefox guys decided to code it that way or it is a bug/feature in specific version.Dry
In my extensive experience maintaining apps that depend on the Host header and testing with both Firefox and Chrome. I've yet to encounter Firefox invisibly adding a www prefix whenever I visit http://sub.domain.localhost. Now both of our experience clashes. I cannot find a citation for your claim, which means your answer is either wrong or you're misinformed and spreading misinformation on a Q/A website simply because "you don't have the time". FYI, citing counter-intuitive claims is good practice to get into, and saying "we're not at the academy" on a help forum isn't.Incuse
Let me tell you. [github] (github.com/mozilla/gecko-dev/blob/…) check this piece of code. This is firefox adds "www" prefix to hostname if it is configured in settings. Then why does firefox adds www to subdomain localhost right? Because firefox thinks it is not an local domain for some reason. Then I googled it and find out that firefox has network.dns.localDomains configuration which enables to firefox to treat subdomains of localhost as local domain. Can we agree firefox adds "www" prefix now?Dry
Yes we can, but it doesn't do it invisibly. Nevertheless, not only have you now given a citation, but you've also given a more complete answer, with a possible solution to OP's question being: "add localhost to firefox's network.dns.localDomains config". I suggest you add that recommendation to your answer. Once you've done that, I'll be able to change my downvote to an upvote. Have a good day.Incuse

© 2022 - 2024 — McMap. All rights reserved.