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.
Related
Couldn't find a question that had this specific setup, so was having trouble making some of the other answers work in my situation.
I have a CentOS server running a PHP-based website with Apache as the web server (working fine). I'm trying to now deploy a Flask-based app (using Gunicorn proxied through Apache) on a different port.
In my main httpd.conf file I have:
<IfModule proxy_module>
# Include the proxy information for VMS Flask Application
Include conf/extra/httpd-foo.conf
</IfModule>
And in my httpd-foo.conf file I have:
ProxyPreserveHost On
ProxyPass /foo http://localhost:8000/
ProxyPassReverse /foo http://localhost:8000/
Timeout 2400
ProxyTimeout 240
PHP website runs at: https://myphpwebsite.com
I'd like the Flask app to run at: https://myphpwebsite.com/foo
The problem I'm encountering is when I visit the Flask URL, is I encounter 2 issues. First, if I don't include a trailing slash after "foo", I get a 404 (because that directory doesn't actually exist in the real web directory. The second issue is that all my Flask routes assume "/" is "root", which it is not now. I don't know how to tell Flask that all routes should have "/foo" pre-pended to them.
Is this possible?
-- Some additional info --
I've tried running the gunicorn command with the "-E" option to tell it the SCRIPT_NAME which seemed to help only for the main page:
gunicorn app:app -b 0.0.0.0:8000 -t 180 -e SCRIPT_NAME=/foo -w 4
Currently, if I visit https://myphpwebsite.com/foo/ it results in a 500 Internal Server Error. I can see that my "not logged in" redirect appears to work and takes me to https://myphpwebsite.com/foo/login properly, but again it's just resulting in a 500 error.
I have kind of the same setup (apache, php, gunicorn, flask), and what works for me is to use VirtualHost and embed the ProxyPass in a Location-directive. So my conf-file looks something like
<VirtualHost *:80>
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPreserveHost On
<Location "/foo">
ProxyPass "http://127.0.0.1:8000/"
ProxyPassReverse "http://127.0.0.1:8000/"
</Location>
</VirtualHost>
This way, calls to https://mydomein.com/ are managed by Apache (managing php als always), and all the requests done to https://mydomein.com/foo are being delegated to GUnicorn (listening on port 8000).
I am attempting to access OrientDB's REST API through a reverse proxy. That is, I have a domain orientdb.mydomain.com that forwards to localhost:2480, where the server is. I have this working on the unsecured website, so I can access http://orientdb.mydomain.com and it brings up the studio site:
http://orientdb.mydomain.com/studio/index.html
However, this does not work through https. I get a 404 error ("The requested URL /studio/index.html was not found on this server")
I have a feeling that I'm not using the correct documentroot or there is something funny about OrientDB that it's generating the path above in another way. I cannot actually find this /studio directory anywhere.
This is from my virtualhost setting in my ssl.conf file.
<VirtualHost _default_:443>
DocumentRoot "/opt/orientdb-3.0.6/www"
<Directory "/opt/orientdb-3.0.6/www">
Require all granted
</Directory>
ServerName orientdb.mydomain.com
#more stuff
</VirtualHost>
By the way, I originally had the following options in my Directory tag, but it gave a forbidden error. I changed it to Require all granted and it now says not found- so I think I'm making progress.
AllowOverride All
Order allow,deny
In summary, is it possible to access the OrientDB server in this way and if so what do I put as DocumentRoot, etc?
I don't think you can do that.
OrientDB has its own HTTP server embedded so the only way it can work is with the reverse proxy configuration.
You can expose your web server (apache HTTP I guess) in https and terminate the "s" there, proxying to orientdb HTTP port (2480).
This turned out not to be an OrientDB issue, but a proxy issue. I had used a virtualhost to set up the proxy on port 80, but I did not do the same for port 443. After adding these settings to my 443 virtualhost on orientdb.mydomain.com, I was able to access the studio and the HTTP REST API through HTTPS.
ProxyPass / http://127.0.0.1:2480/
ProxyPassReverse / http://127.0.0.1:2480/
<Proxy *>
Require all granted
</Proxy>
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.
I'm currently running a websocket server. I want to be able to access this through ws.mydomain.com
The web socket is listening on port 8080.
I'm running Apache 2.4 and my configuration looks look this.
<VirtualHost *:80>
ServerName ws.mydomain.com
ProxyRequests Off
<Location />
ProxyPass ws://xxx.xxx.x.xx:8080/
</Location>
</VirtualHost>
when I try to connect on websocket.org it won't let me while I'm pretty sure they are doing something similar theirself in their example.
Does anyone know what might be going wrong here?
So I have an application the is bound to localhost:3080. When I locally visit "localhost:3080" the application displays in the browser.
I also have an apache server setup listening to the publicIP:8080.
When I visit the publicIP from the outside world, publicIP:8080 loads up.
How can I have it so that when I visit publicIP:8080, the contents of localhost:3080 are displayed onto it?
Is there a way to forward the contents of localhost:3080 to publicIP:8080?
You can create an apache proxy.For example :
<VirtualHost *:8080>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:3080/
ProxyPassReverse / http://127.0.0.1:3080/
</VirtualHost>
You will also need to do :
a2enmod proxy
a2enmod proxy_http
service apache2 restart
See more informations there : https://www.digitalocean.com/community/tutorials/how-to-use-apache-http-server-as-reverse-proxy-using-mod_proxy-extension
I assume your application at localhost:3080 acts as a http server.
Then you would simply
ProxyPass "/" "http://localhost:3080/"
Generally its better to use ProxyPass to handle only special locations
<Location "/myCoolApp/">
ProxyPass "http://localhost:3080/"
</Location>
Then if you request http://publicIP:8080/myCoolApp/XYZ your application #3080 will receive the request on URL /XYZ.