I need help to enable wss in with google compute engine instance ip. My google cloud compute engine instance ip is: 35.192.96.70
I started ratchet server like this:
$allowed_origins = ['localhost','35.192.96.70', '127.0.0.1'];
$app = new Ratchet\App('35.192.96.70', 8080, '0.0.0.0');//App(hostname, port, 'whoCanConnectIP', '')
$app->route('/comm', new Comm, $allowed_origins);
$app->run();
and in js file I'm connecting to websocket server like this:
const wsChat = new WebSocket("wss://35.192.96.70:8080/comm");
but its not connecting. But if I use 'ws' instead of 'wss' like this:
const wsChat = new WebSocket("ws://35.192.96.70:8080/comm");
then its working.
I need help how to make wss work. What changes/settings I need to do in google cloud dashboard or in apache setting or else ?
Thanks for help,
If on SSL, Ratchet won't work unless you make some changes on your server.
Enable mod_proxy.so
Enable mod_proxy_wstunnel.so
Open httpd.conf and add this: ProxyPass /wss2/ ws://YOUR_SERVER_IP_OR_DOMAIN:PORT/
e.g. ProxyPass /wss2/ ws://www.abc.xyz:8080/
From your front-end, you can connect like this:
const wsChat = new WebSocket("wss://YOUR_SERVER_IP_OR_DOMAIN/wss2/comm");
However, if you are wondering how to edit httpd.conf on WHM, here is how:
After enabling those services (mod_proxy.so and mod_proxy_wstunnel.so), log in to WHM,
go to "service configuration" => "Apache configuration" => "include editor" => "pre main include",
select a version of your choice or choose "All versions". The file name should be "pre_main_global.conf'
All your new configuration can be written in that textarea without tampering with httpd.conf directly. The configurations will be loaded on Apache start-up.
Once you put the Proxypass directive there, restart your server and there you go.
Related
I am trying to use QuotaGuard Static IPs to host a Next.js application. The Next API routes are running Prisma which, in turn is making direct db requests to a protected Microsoft SQL Server.
The client has whitelisted my IP for local development and the app works fine. But on Heroku you can't get a static IP without the QuotaGard.
I don't believe I have set up the QuotaGuard correctly or the server.js file. The rest of the app is working fine. Here are those files:
Expected Behavior:
The server proxies its url to one provided by the QuotaGuard
The MS Sql Server can whitelist the IP
Next.js server.js uses the 'http-proxy-middleware' to proxy requests
Actual Behavior:
The app homepage just shows 'this is a proxy server'
The QuotaGuard dashboard does not show any requests
The prisma client cannot connect (connection refused)
// server.js
// BASICALLY A COMBO OF THESE TWO OPTIONS:
// - https://quotaguard.freshdesk.com/support/solutions/articles/5000013744-getting-started-with-node-js-standard-http-library-quotaguard
// - https://medium.com/bb-tutorials-and-thoughts/next-js-how-to-proxy-to-backend-server-987174737331
const express = require('express')
const { parse } = require('url')
const next = require('next')
const { createProxyMiddleware } = require('http-proxy-middleware')
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
// proxy middleware options
const options = {
target: process.env.QUOTAGUARDSTATIC_URL, // target host
changeOrigin: true, // needed for virtual hosted sites
ws: true, // proxy websockets
}
app.prepare()
.then(() => {
const server = express()
if (!dev) {
server.use('*', createProxyMiddleware({ ...options }))
}
server.all('*', (req, res) => {
const parsedUrl = parse(req.url, true)
return handle(req, res, parsedUrl)
})
server.listen(process.env.PORT, (err) => {
if (err) throw err
console.log(`> Ready on http://localhost:${process.env.PORT}`)
})
})
.catch((err) => {
console.log('Error:::::', err)
})
You can see the live app at https://planes-planner-staging.herokuapp.com/
In this case, based on what you shared, you are close, but you need to go with the SOCKS proxy using the QuotaGuard QGTunnel software.
Steps to set that up are :
Download QGTunnel into the root of your project
curl https://s3.amazonaws.com/quotaguard/qgtunnel-latest.tar.gz | tar xz
Log in to the QuotaGuard dashboard and setup the tunnel
Since you are using Heroku, you can use the Heroku CLI to log into the dashboard with the following command:
heroku addons:open quotaguardstatic
Or if you prefer, you can login from the Heroku dashboard by clicking on QuotaGuard Static on the resources tab of your application.
Once you are logged into the dashboard, in the top right menu, go to Setup (Gear Icon), click on QGTunnel Configuration, then Create Tunnel.
Remote Destination: tcp://hostname.for.your.server.com:1433
Local Port: 1433
Transparent: true
Encrypted: false
This setup assumes that the remote mssql server is located at hostname.for.your.server.com and is listening on port 1433. This is usually the default port.
The Local Port is the port number that QGTunnel will listen on.
In this example we set it to 5432, but if you have another process using 1433, you may have to change it (ie: 1434).
Transparent mode allows QGTunnel to override the DNS for hostname.for.your.server.com to 127.0.0.1, which redirects traffic to the QGTunnel software. This means you can connect to either hostname.for.your.server.com or 127.0.0.1 to connect through the tunnel.
Encrypted mode can be used to encrypt data end-to-end, but if your protocol is already encrypted then you don't need to spend time setting it up.
Change your code to connect through the tunnel
With transparent mode and matching Local and Remote ports you should not need to change your code. You can also connect to 127.0.0.1:1433.
Without transparent mode, you will want to connect to 127.0.0.1:1433.
Change your startup code
Change the code that starts up your application. In Heroku, this is done with a Procfile. Basically you just need to prepend your startup code with "bin/qgtunnel".
So for a Procfile that was previously:
web: your-application your arguments
you would now want:
web: bin/qgtunnel your-application your arguments
If you do not have a Procfile, then Heroku is using a default setup in place of the Procfile based on the framework or language you are using. You can usually find this information on the Overview tab of the application in Heroku's dashboard. It is usually under the heading "Dyno information".
Commit and push your code
Be sure that the file bin/qgtunnel is added to your repository.
If you are using transparent mode, be sure that vendor/nss_wrapper/libnss_wrapper.so is also added to your repository.
If you are not using transparent mode, you will want to set the environment variable QGTUNNEL_DNSMODE to DISABLED to avoid seeing an error message in your logs.
If you have problems...
Enable the environment variable QGTUNNEL_DEBUG=true and then restart your application while watching the logs.
VERY IMPORTANT
After you get everything working
Download your QGTunnel configuration from the dashboard as a .qgtunnel file and put that in the root of your project. This prevents your project from relying on the QG website during startup.
Alternatively you can put the contents of the downloaded configuration file in a QGTUNNEL_CONFIG environment variable.
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?!
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.
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
I've been developing with the vue-cli and the Webpack template. Everything works flawlessly but I'm having some issues using a custom host. Right now Webpack listens to localhost:8080 (or similar) and I want to be able to use a custom domain such as http://project.dev. Has anybody figured this out?
This might be where the problem resides:
https://github.com/chimurai/http-proxy-middleware
I also added this to the proxyTable:
proxyTable: { 'localhost:8080' : 'http://host.dev' } and it gives me a console response [HPM] Proxy Created / -> http://host.dev
Any advice, direction or suggestion would be great!
Update
I successfully added a proxy to my Webppack project this way:
var mProxy = proxyMiddleware('/', {
target: 'http://something.dev',
changeOrigin: true,
logLevel: 'debug'
})
app.use(mProxy)
This seems to work, but still not on port 80.
Console Log:
[HPM] Proxy created: / -> http://something.dev
I can assume the proxy is working! But my assets are not loaded when I access the url.
Is important to note I'm used to working with Mamp -- and its using port 80. So the only way I can run this proxy is to shut down Mamp and set the port to 80. It seems to work, but when I reload page with the proxy URL -- there is a little delay, trying to resolve, and then console outputs this:
[HPM] GET / -> http://mmm-vue-ktest.dev
[HPM] PROXY ERROR: ECONNRESET. something.dev -> http://something.dev/
And this displays in the browser:
Error occured while trying to proxy to: mmm-vue-ktest.dev/
The proxy table is for forwarding requests to another server, like a development API server.
If you want the webpack dev server to run on this address, you have to add it to your OS's hosts file. Vue or we pack can't do this, it's the job of your OS.
Google will have simple guides for every OS.
Im developing an app with CodeIgniter, mainly for learning purposes.
Im currently addressing the issue of security in my app and one thing I read about is using SSL.
I tried to figure out what I have to do in order to use SSL in my app. Since I'll have a small number of users I thought about using SSL on all of my sites.
In another question for SSL in CI I found this:
$config['base_url'] = "https://www.yoursite.com/";
Is this all I have to configure to use SSL? Do I have to buy a certificate somewhere? Are there any prerequisites for my server?
Thanks in advance for your help!
SSL is related to your server. Not to your server side scripting software, i.e. php.
So, you should be looking for ssl for your server software.
Now, you have two options:
If you run in a local intranet, you could use software like xampp which by default provides https functionality for apache through self signed ssl certificate.
If you are using a hosting account, you should get a signed ssl certificate.
And ofcourse the setting in codeigniter, which you specified must be set to actually make use of the https.
You will need an SSL certificate for this yeah. Most current servers can handle these just fine, although your server needs an personal IP-address for this.
Open config file from location application/config/config.php and enable or set hooks to true like this:
$config['enable_hooks'] = TRUE;
Then create a new file named hooks.php inside the config folder (i.e. application/config/hooks.php) and add the following code in it:
$hook['post_controller_constructor'][] = array(
'function' => 'redirect_ssl',
'filename' => 'ssl.php',
'filepath' => 'hooks'
);
**Now create a new directory named hooks inside the application folder (i.e. application/hooks) and then create a new file named ssl.php inside the hooks folder (i.e. application/hooks/ssl.php).
Add the following code in the ssl.php file:**
function redirect_ssl() {
$CI =& get_instance();
$class = $CI->router->fetch_class();
$exclude = array('client'); // add more controller name to exclude ssl.
if(!in_array($class,$exclude)) {
// redirecting to ssl.
$CI->config->config['base_url'] = str_replace('http://', 'https://', $CI->config->config['base_url']);
if ($_SERVER['SERVER_PORT'] != 443) redirect($CI->uri->uri_string());
} else {
// redirecting with no ssl.
$CI->config->config['base_url'] = str_replace('https://', 'http://', $CI->config->config['base_url']);
if ($_SERVER['SERVER_PORT'] == 443) redirect($CI->uri->uri_string());
}
}
i am working on cakephp.
I have developed an application where i have used localhost in all ajax post and get..
like
var ht = $.ajax({
type: "GET",
url: "http://localhost/FormBuilder/index.php/forms/getInvitees/<?php echo $emailid;?>",
async: false
}).responseText;
var myObject = eval('(' + ht + ')');
this thing works only when i put localhost . But when i change that to my Ip like
http://111.11.11.11/FormBuilder/index.php/forms/getInvitees/",
then i am getting a syntax error () in the line
var myObject = eval('(' + ht + ')');
WHy it happens ?? Please give valuable suggestions in solving this..
The response for ht will be
{"invitees":[{"invitee":"23"}]}
from which i will generate a link by
var data = myObject;
$.map(data.invitees, function(i){
var id=i.invitee;
$("<a href=<?php echo $link?>/"+id+"/Invitee> <?php echo $link?>/"+id+"/Invitee</a>").appendTo("#"+inc);
inc++;
return i.invitee;});
Thank you
You know that localhost translates to 127.0.0.1 in almost any case. Did you make sure to setup your webserver to bind to 111.11.11.11 correctly and serve the same DocumentRoot?
Looks like your not getting a JSON object back when calling the server via IP.
EDIT
I don't know whether or not you are using VirtualHosts to set up your development environment but since you're making use of localhost I will go with Apache's standard httpd.conf.
In the httpd.conf file search for a line that start with Listen .... Make sure that the only line with a Listen directive looks like Listen *:80, to allow Apache to bind itself to any of the IPs available on your machine.
Then, insert the following near the end of the file:
<VirtualHost *>
ServerName myfoo.com
ServerAdmin admin#myfoo.com
DocumentRoot "C:/..path to your working directory/"
</VirtualHost>
Now you have successfully implemented a VirtualHost that serves localhost and any other IP your machine is assigned to from the same DocumentRoot (the directory your HTML/PHP/whatever files reside in).
Good luck.
Surely using localhost is more generic in this case?
In my CakePHP apps, I use:
'http://localhost/cakeapp/nodeDescriptors/ajaxSetStatus'
or
'/cakeapp/nodes/updateTreeNodes'
for AJAX calls.
Remember you'll run into problems if you try to access a different domain directly. Perhaps that is what's happening with your IP-based call?
Localhost will only work from your local machine, but mind you, your app will eventually be accessed from out side , where localhost would be the clients machine..
You need to specify the public IP address or the domain name or the network name if you use an internal DNS for an intranet app.