I'm trying to set up websocket on my local machine to test it but I simply can't get it to work, nor find any guide that actually solves it.
So to sum up, can anyone tell me what's wrong with my settings?
I'm running Ububtu 16.04 and Apache 2.4.18
I have mod_proxy and mod_proxy_wstunnel enabeled
my Apache config looks like this
<VirtualHost *:80>
ServerName socket.localhost
ProxyRequests Off
ProxyPass "/ws2/" "ws://localhost:8546/"
ProxyPass "/wss2/" "wss://localhost:8546/"
</VirtualHost>
On the client side I have this javaScript
<script type="text/javascript">
var socket = new WebSocket('ws://socket.localhost');
socket.send('Test');
</script>
And I'm running
netcat -p 8546 -l
To see any connection
And lastly I have this line in my hosts file
127.0.0.1 socket.localhost
Whenever I run the JavaScript I get the error
Firefox can’t establish a connection to the server at ws://socket.localhost/.
You javascript code should utilize the address ws://socket.localhost/ws2, since this is what you have configured in the Apache proxy configuration.
Do you actually have a websocket server running at ws://localhost:8546? You don't mention that in your description.
Related
I have a CentOs 7.1 with Apache httpd running on port 9000.
So if i type in my browser: http://192.168.56.101:9000/ I see the Apache Testing 123 Page.
I also have a GitLab Server running on port 8888, but this port is closed by the firewall.
I want that Apache redirects traffic to http://192.168.56.101:9000/gitlab internally to the GitLab server.
I have done this in my Apache config file /etc/httpd/conf/httpd.conf:
<VirtualHost *:9000>
ProxyPass /gitlab http://192.168.56.101:8888/users/sign_in
ProxyPassReverse /gitlab http://192.168.56.101:8888/users/sign_in
</VirtualHost>
When users browse to http://192.168.56.101:9000/gitlab the login page appears (css seems broken though), but when logging in this appears:
Not Found
The requested URL /users/sign_in was not found on this server.
Is this something that is configurable with Apache and if so how?
Do I need to use some sort of Url-Rewriting, if yes which and how to get started?
All the links in gitlab will presume you are pointing at the original server.
So you need to look at mod_proxy_html to also replace these links in the HTML:
https://httpd.apache.org/docs/2.4/mod/mod_proxy_html.html
I've been having problems attempting to implement a reverse SSL proxy on Apache for an HTTP application on Ubuntu 14.04. As a baseline, the application works fine when I access it via port 8000 in the browser normally. For all intents and purposes, let's say the IP of my app is 192.141.56.11 (I do not have a domain name yet). The application runs with HTTP Basic Auth, I don't know if it's relevant. Basically I'm fishing for some glaring error here and would be grateful if you could help me out. Here is a log of my process:
I created my SSL cert and key and put them in the following locations:
/etc/apache/ssl/apache.crt (I performed chmod 644 here)
/etc/apache/ssl/apache.key (I performed chmod 400 here)
I then installed:
apt-get install apache2
a2enmod proxy
a2enmod ssl
a2enmod proxy_http
I then disabled the default config with:
a2dissite 000-default
I created the file "/etc/apache2/sites-available/redirect.conf"
I then created the file "/etc/apache2/sites-available/redirect.conf" and copied the text below:
<VirtualHost *:80>
Redirect "/" "https://192.141.56.11"
</VirtualHost>
After, I created the file "/etc/apache2/sites-available/reverse_proxy.conf" and copied below:
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/apache/ssl/apache.crt
SSLCertificateKeyFile /etc/apache/ssl/apache.key
ProxyPass / http://127.0.0.1:8000/
ProxyPassReverse / http://127.0.0.1:8000/
and did:
service apache2 restart
I now attempt to access the UI of the application on another machine in the Chrome browser. When trying:
https://192.141.56.11
I get a general SSL connection error.
However, trying
http://192.141.56.11:8000
gives me the application, as if none of my config changed anything. However,
192.141.56.11:80
gives me an "Index Of" page with an html folder that says "Apache/2.4.7 (Ubuntu) Server at 192.141.56.11 Port 80"
192.141.56.11:443
gives me the same result except with "Apache/2.4.7 (Ubuntu) Server at 192.141.56.11 Port 443"
I've tried all manners of configurations but can't get what I want -- any ideas here?
EDIT: I tried https[:]//192.141.56.11 and got a more specific SSL error:
received a record that exceeded the maximum permissible length. (Error code: ssl_error_rx_record_too_long)
EDIT2: After running apache, I get this warning;
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
I suppose this is fine as I am using an IP and not a domain name.
EDIT3: It turns out I needed to do:
a2ensite reverse_proxy.conf.
Now https[:]//192.141.56.11 works but defaults to an apache page. working on this.
EDIT4: I had to do
a2dissite default-ssl.conf
Now It actually redirects to the app on https[:]//192.141.56.11!! But I can still access the app via port 8000, which is bad {still working on}
EDIT5: IN the end, I couldn't figure out how to block access to the original app via port 8000 on Apache. Instead, I just implemented iptables on the server so that it can only be accessed via HTTPS. This is probably not the correct method. but all I could think of.
I'm trying to setup my local development environment and I'm only missing one piece of the puzzle.
I was able to successfully install the following on my Mac OSX 10.7.5 x86_x64
XAMPP - http://www.apachefriends.org/en/xampp-macosx.html
ColdFusion 10 - Developer Edition
Both are running fine. I was able to pull up localhost (Apache) and localhost:8500 (ColdFusion) - my ajp connector port is 8012
Now I want to be able to pass the request to my ColdFusion from Apache using mod_proxy_ajp.
I created an index.cfm file on the wwwroot/cf directory of ColdFusion, enabled the NameVirtualHost and created a VirtualHost directive in Apache that looks like this:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost
<Location "/cf">
Allow from all
ProxyPass ajp://localhost:8012/
</Location>
</VirtualHost>
After restarting everything, I get a 503 error.
Any help or pointers is much appreciated.
Thanks!
check your CF logs:
{cf_root}/cfusion/logs/coldfusion-error.log
You probably have something like this in the log:
org.apache.coyote.ajp.AjpProcessor getRealPathFromServer
SEVERE: Error in getRealPathFromConn
java.io.IOException: Socket read failed
So mod_proxy_ajp is passing the request to Tomcat, but Tomcat can't read it.
Have you tried configuring with mod_jk instead?
http://helpx.adobe.com/coldfusion/kb/coldfusion10-apache-manual-connector-configuration.html
Might not be the way you want to configure it, but it should get you up and running.
I dont have much experience neither in Node.js not in socket.io, thus maybe I will ask silly questions and sorry for that first of all.
I am trying to do following:
Installed node on ubuntu where I have apache also installed.
Created virtual host in apache and set it as proxy to node. My conf file looks like:
<VirtualHost *:80>
ServerAdmin giorgi#omedia.ge
ServerName node.aidemo.info
ServerAlias www.node.aidemo.info
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://127.0.0.1:8080
ProxyPassReverse http://127.0.0.1:8080
</Location>
</VirtualHost>
Have created simple js file for server (first server example in socket.io website) and started server from cli with command: node server.js.
It starts perfectly and listens to 8080
Created another virtualhost where I put clientside index.html (also from first example in socket.io). At first I had problem (and actually main problem is this), browser couldn't resolve path /socket.io/socket.io.js. Then I went to the url (http://localhost:8080/socket.io/socket.io.js) from lynx locally from terminal, downloaded that js and put locally with virtualhost near index.html. After this, browser could resolve that request, but I have error when socket.io.js itself is trying to get the url:
http://localhost:8080/socket.io/1/?t=1347623348836
Do you have any ideas how can I solve this problem?
My main goal is to have web url from which I can access my node server and talk with it with socket.io - for example to create very simple chat.
I hope I was clear.
Thank you everyone who will try to help.
I am using express + socket.io and they are listening on port 3001. And I want http://example.com/folder to redirect to my Express app listening on port 3001 (i.e, to http://localhost:3001, server-side).
I have done the following.
The .html file has this:
<script src='/folder/socket.io/socket.io.js'> </script>
<script>
var socket = io.connect('http://example.com', {resource: 'folder/socket.io'});
...
</script>
And my apache2 conf looks like this:
ProxyPreserveHost On
ProxyPass /folder/ http://localhost:3001/
ProxyPassReverse /folder/ http://localhost:3001/
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location /folder/>
allow from all
</Location>
Note that it requires the module proxy_http to be enabled. To enable it, run this command:
sudo a2enmod proxy_http; service apache2 restart
If you put socket.io.js file locally near your index.html file, it will not resolve the problem because you probably didn't change the url in your socket var in main.js file, look at:
var socket = io.connect();
in your main.js/index.html (script)
replace with:
var socket = io.connect(httpprotocol+hostname+httpport);
My code source look like this:
var socket = io.connect('https://192.168.43.187:8443/');
http://localhost:8080 is obviously not going to be available to anything outside of your server.
The client-side javascript's io.connect() should be connecting to http://node.aidemo.info so that apache can send that off to Node.
http://node.aidemo.info:8080 might also work if you've opened up port 8080.
My work runs a couple different internal web apps on an ubuntu server (10.10) running apache. I'm currently developing another web app, and am seriously considering developing on top of a custom-built node.js web server. My reasoning for wanting to do this is:
Speed/Scalability
Security - Pages will be served with a switch...case, instead of just serving the (potentially malicious) user whatever they ask for.
Ease of setup - my intentions are for this to be an open-source project, and node.js is much easier for users to set up, rather than dealing with apache/IIS/etc.
My question is, on a server where I've got apache listening to port 80, how can I pass off a certain subdomains to node.js. I've seen a couple articles about using apache virtual hosts to pass it off, but that seems to defeat the purpose of using node.js. If I have to go through apache, then all three of my reasons for avoiding apache/IIS have voided themselves.
I know I could use a different port (:8080?), but from an end-user standpoint, it's pretty confusing having to put in custom ports. Any alternative ideas?
Thanks
<VirtualHost *:80>
ServerName subdomain.yourdomain.com
ProxyPreserveHost on
ProxyPass / http://localhost:8080/
</VirtualHost>
Thanks to http://www.chrisshiplet.com/2013/how-to-use-node-js-with-apache-on-port-80/
if socket.io node is running, be sure to enable also few apache mods:
a2enmod proxy
a2enmod proxy_balancer
a2enmod proxy_express
a2enmod proxy_http
in file /etc/apache2/sites-available/chat.example.com.conf
<VirtualHost *:80>
ServerName chat.example.com
<Location "/">
ProxyPreserveHost On
ProxyPass http://localhost:3000/
ProxyPassReverse http://localhost:3000/
</Location>
</VirtualHost>
then of course service apache2 reload
How about doing things the other way round : bind node to port 80, handle the traffic targeted at the subdomain and use it as a reverse proxy to apache for everything else ?
Let me start from the ground up:
You have a DNS. And a dns server maps one DNS to one IP!
You then have apache running on your computer that listens for connections on port 80 for http:// and on port 443 for https://. http://example/ is actually a request on http://example:80/.
You can't use node.js to listen on the same machine on the same port as apache. That's why using port 8080 is viable.
You can also map the subdomain to a different IP. The only caveat here is that you need to have a public IP Address.
You can't serve port 80 from both Apache and node.js. Having Apache as a reverse proxy wouldn't be much efficient and that's why nginx is popular in this scenario. Other alternative than nginx based reverse proxy can be as Khez suggested mapping your subdomain to different IP address which will node.js program listen to or maybe use node.js itself as a reverse proxy for Apache.
You could configure a virtual host in apache for your new site and add a permanent redirect within it to the localhost and port used by node.js.
This is how I do it on a server with several other virtual hosts and my node.js application running on port 3000:
NameVirtualHost *:80
[Other virtual hosts omitted for brevity]
...
ServerName mynewsite.com
RedirectMatch (.*) http://localhost:3000$1