localhost refuses to connect - ERR_CONNECTION_REFUSED

删除回忆录丶 提交于 2021-02-09 11:13:46

问题


I have a simple MVC web application where javascript code sends ajax requests to the controller and the controller sends back responses.

I built the app 2 years ago and everything used to work fine. Now I tried to run the app again locally and met with the following problem: whenever an Ajax request is sent from the frontend to the controller (running on localhost), the localhost refuses to connect and I get an ERR_CONNECTION_REFUSED message in (chrome's) javascript-console. (In Safari's javascript-console I get the following error message: "Failed to load resource: Could not connect to the server.")

I'm running the app using NetBeans 11.2. My NetBeans IDE uses GlassFish as server:

I removed the Glassfish server from NetBeans IDE, deleted its folder in my home directory and then added the Glassfish server again in my NetBeans IDE (which also entailed downloading the the newest version of the Glassfish server).

Still, the server refuses to accept any requests from the frontend.

I also tried using Payara Server (version 5.193). That didn't make a difference either.

The frontend itself looks fine at first glance by the way. That is, going to http://localhost:8080/myapp loads the frontend of the app. However, any dynamic features of the app don't work because the server refuses to accept any Ajax requests coming from the frontend (and initiated through mouse clicks).

How can I fix this?


I think I found the reason for the problem:

In my javascript-file I have the following line of code:

var url = "http://localhost:8080/myapp/Controller";

The variable "url" is passed to all the AJAX requests sent to localhost. But here is the crazy thing: the AJAX requests are not sent to "http://localhost:8080/myapp/Controller" but to "http://localhost:8081/myapp/Controller" !!!!!

What the hell is going on here?!


回答1:


Did you use port 8081 before and then changed the variable "url" to the new port 8080? In this case, maybe the variable is still set to the old value in the cache. Restart your computer and see whether this fixes the problem.




回答2:


If the value of the attribute http-listener is localhost, it will refuse the connection external connection.

You can verify using its value using the command

asadmin> get server-config.network-config.network-listeners.network-listener.http-listener-1.*

Information similar to the following should returned:

server.http-service.http-listener.http-listener-1.acceptor-threads = 1
server.http-service.http-listener.http-listener-1.address = 0.0.0.0
server.http-service.http-listener.http-listener-1.blocking-enabled = false
server.http-service.http-listener.http-listener-1.default-virtual-server = server
server.http-service.http-listener.http-listener-1.enabled = true
server.http-service.http-listener.http-listener-1.external-port =
server.http-service.http-listener.http-listener-1.family = inet
server.http-service.http-listener.http-listener-1.id = http-listener-1
server.http-service.http-listener.http-listener-1.port = 8080
server.http-service.http-listener.http-listener-1.redirect-port =
server.http-service.http-listener.http-listener-1.security-enabled = false
server.http-service.http-listener.http-listener-1.server-name =
server.http-service.http-listener.http-listener-1.xpowered-by = true

Modify an attribute by using the set subcommand.

This example sets the address attribute of http-listener-1 to 0.0.0.0:

asadmin> set server.http-service.http-listener.http-listener-1.address = 0.0.0.0

Reference:

https://docs.oracle.com/cd/E19798-01/821-1751/ablaq/index.html



来源:https://stackoverflow.com/questions/60158617/localhost-refuses-to-connect-err-connection-refused

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!