Start Padrino on different host (virtual) - rack

I start WEBrick server through Padrino by this command: padrino start
It listens on localhost, but I would like to use WEBrick virtual hosts to change this behaviour to respond to other hostnames like example.com. But padrino start doesn't have these options. How can I pass virtual hosts details to WEBrick?

It actually does have an option to do so.
bundle exec padrino start -h example.com
should bind to example.com for listening.

Related

How to access Mongodb in AWS EC2 Ubuntu from my laptop [duplicate]

I've successfully installed MongoDB on Windows (on a local machine) as a service, but now I want to move MongoDb to a separate server. So I extracted the tarball to a virtual server on network (running linux).
When I connected to the server ("testmongoserver") using PuTTY from my local machine, I started the mongod server and it told me that it was listening to the default 28017 port. The mongo console is also working and allowed me to create a new database (testdb) and add users to it.
However, I could not access the server from remote. When I type testmongoserver:28017 it doesn't open the HTTP console as localhost:28017 on my local machine does. I also can't connect using official drivers and providing a connectionstring.
What are the neccesarry steps to install MongoDB on Linux, so that I could access it from a remote machine with a connectionstring and use its HTTP console via testmongoserver:28017
Thanks!
1. Bind IP option
Bind IP is a MongoDB option that restricts connections to specifics IPs.
Have a look at your mongod configuration file, most of the time bind_ip is set to 127.0.0.1 for obvious security reasons. You can:
Add your desired IP by concatenating a list of comma separated values to bind MongoDB to multiple IP addresses.
Remove or comment (with # character) the bind_ip line. But be aware that all remote connection will be able to connect your MongoDB server!
More about bind_ip configuration option: https://docs.mongodb.com/manual/reference/configuration-options/#net.bindIp
Bind IP can also be set as a command argument: http://docs.mongodb.org/manual/reference/program/mongod/#cmdoption--bind_ip
2. Firewall
Check that you are not running behind a firewall
Make sure in your /etc/mongodb.conf file you have the following line,
bind_ip = 0.0.0.0
http://jitu-blog.blogspot.com.br/2013/06/allow-mongo-to-connect-from-remote-ip.html
Run netstat -a on mongo server and check a port.
Check DNS settings and check that linux server allows external connections.
Check that mongodb can accept external/remote connection.
Default port for mongo is 27017.
28017 - port for webstats.
See http://www.mongodb.org/display/DOCS/Security+and+Authentication#SecurityandAuthentication-Ports
Just had this issue and this fixed it:
Edit /etc/mongod.conf with sudo nano /etc/mongod.conf ensure that the net section looks like below (localhost binding by default doesn't allow for remote access):
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0
Make sure to restart mongod when you are done with above with below (assuming systemd ubuntu 16.04+ etc.):
sudo service mongod restart
Obviously from a security perspective if you are going to be opening up mongo to your network/the world be aware of the implications of this (if any)
Another problem may be that the mongodb port is not enabled. Check, from another host, the ports enabled on your server. For that you can use the command:
sudo nmap -P0 your_server_ip
You can get an answer like this:
Host is up (0.052s latency).
Not shown: 997 filtered ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
443/tcp closed https
If you use a virtual server in the cloud, as AWS, you need to add a new rule to add mongodb port (27017 by default).
Important: Note that with this configuration anyone can have access to your database
I fixed by below reference :
https://medium.com/founding-ithaka/setting-up-and-connecting-to-a-remote-mongodb-database-5df754a4da89
Actually, first i changed my bindIp from 127.0.0.1 to 0.0.0.0 in mongod.conf,
and enable security:
security:
authorization: "enabled"
then i restarted mongod using sudo service mongod restart.(because of new changes in mongod.conf), after that set firewall to open mongod running port (by iptables) and create a new user in admin db with new access (based on this link : https://medium.com/mongoaudit/how-to-enable-authentication-on-mongodb-b9e8a924efac), finally test open ports in my server from outside with (https://www.yougetsignal.com/tools/open-ports/) and connected successfully to remote mongod using mongocompass.exe.

mongodb only connect by localhost [duplicate]

I've successfully installed MongoDB on Windows (on a local machine) as a service, but now I want to move MongoDb to a separate server. So I extracted the tarball to a virtual server on network (running linux).
When I connected to the server ("testmongoserver") using PuTTY from my local machine, I started the mongod server and it told me that it was listening to the default 28017 port. The mongo console is also working and allowed me to create a new database (testdb) and add users to it.
However, I could not access the server from remote. When I type testmongoserver:28017 it doesn't open the HTTP console as localhost:28017 on my local machine does. I also can't connect using official drivers and providing a connectionstring.
What are the neccesarry steps to install MongoDB on Linux, so that I could access it from a remote machine with a connectionstring and use its HTTP console via testmongoserver:28017
Thanks!
1. Bind IP option
Bind IP is a MongoDB option that restricts connections to specifics IPs.
Have a look at your mongod configuration file, most of the time bind_ip is set to 127.0.0.1 for obvious security reasons. You can:
Add your desired IP by concatenating a list of comma separated values to bind MongoDB to multiple IP addresses.
Remove or comment (with # character) the bind_ip line. But be aware that all remote connection will be able to connect your MongoDB server!
More about bind_ip configuration option: https://docs.mongodb.com/manual/reference/configuration-options/#net.bindIp
Bind IP can also be set as a command argument: http://docs.mongodb.org/manual/reference/program/mongod/#cmdoption--bind_ip
2. Firewall
Check that you are not running behind a firewall
Make sure in your /etc/mongodb.conf file you have the following line,
bind_ip = 0.0.0.0
http://jitu-blog.blogspot.com.br/2013/06/allow-mongo-to-connect-from-remote-ip.html
Run netstat -a on mongo server and check a port.
Check DNS settings and check that linux server allows external connections.
Check that mongodb can accept external/remote connection.
Default port for mongo is 27017.
28017 - port for webstats.
See http://www.mongodb.org/display/DOCS/Security+and+Authentication#SecurityandAuthentication-Ports
Just had this issue and this fixed it:
Edit /etc/mongod.conf with sudo nano /etc/mongod.conf ensure that the net section looks like below (localhost binding by default doesn't allow for remote access):
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0
Make sure to restart mongod when you are done with above with below (assuming systemd ubuntu 16.04+ etc.):
sudo service mongod restart
Obviously from a security perspective if you are going to be opening up mongo to your network/the world be aware of the implications of this (if any)
Another problem may be that the mongodb port is not enabled. Check, from another host, the ports enabled on your server. For that you can use the command:
sudo nmap -P0 your_server_ip
You can get an answer like this:
Host is up (0.052s latency).
Not shown: 997 filtered ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
443/tcp closed https
If you use a virtual server in the cloud, as AWS, you need to add a new rule to add mongodb port (27017 by default).
Important: Note that with this configuration anyone can have access to your database
I fixed by below reference :
https://medium.com/founding-ithaka/setting-up-and-connecting-to-a-remote-mongodb-database-5df754a4da89
Actually, first i changed my bindIp from 127.0.0.1 to 0.0.0.0 in mongod.conf,
and enable security:
security:
authorization: "enabled"
then i restarted mongod using sudo service mongod restart.(because of new changes in mongod.conf), after that set firewall to open mongod running port (by iptables) and create a new user in admin db with new access (based on this link : https://medium.com/mongoaudit/how-to-enable-authentication-on-mongodb-b9e8a924efac), finally test open ports in my server from outside with (https://www.yougetsignal.com/tools/open-ports/) and connected successfully to remote mongod using mongocompass.exe.

Bind MongoDB to IP address when running as Service

I am new to MongoDB, so excuse me for a basic question but.
I am running MongoDB (3.6, Professional) on a Windows PC. I have managed to add it as a Windows Service to start automatically on Startup.
However, it binds to 127.0.0.1 or localhost.
The IP on that PC is 192.168.1.10 and I would like to access the server from different LAN PCs.
When I run Mongo, I get:
WARNING: This server is bound to localhost. Remote systems will be
unable to connect to this server. Start the server with --bind_ip
to specify which IP
addresses it should serve responses from, or with --bind_ip_all to
bind to all interfaces. If this behavior is desired, start the
server with --bind_ip 127.0.0.1 to disable this warning.
So I went to Services.msc, and added --bind_ip_all as a parameter, and restarted the service. But get the same warning. How can I get my MongoDB service to bind to all, or better yet, bind_ip = 127.0.0.1,192.168.1.10?
I may have resolved this, but not sure if it's the right way.
I removed the service.
I recreated the service, but added a conf parameter and provided a
path to my config file.
C:\Program Files\MongoDB\Server\3.6\bin>mongod
--dbpath=C:\Storage\database\mongodb\data --logpath=C:\Storage\database\mongodb\logs --config "C:\Program Files\MongoDB\Server\3.6\bin\mongod.conf" --install
I created a config file:
Listen to local and LAN interfaces.
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1,192.168.1.10 # Listen to local interface only, comment to listen on all interfaces.
It seems I can now bind to both localhost and my IP address..

Change Name of MongoDB Server

In MongoDB, how do I change the name of the server/daemon, or create a new server with a name other than localhost? The docs specify a way to connect to a server with a specific name, such as localhost (the --host option on the mongo command), as well as a way to specify the names of each server in a replication set, which I forget at the moment, but not a method to say the name of the server to create an instance of for the mongod command. It seems to have to be localhost.
I have node.js and apache, so I can use virtual hosting, and I obviously have a hosts file (/etc/hosts on Unix-like OS's and C:\WINDOWS\System32\drivers\etc\hosts on Windows), so I can presumably create a server with a different name from localhost, but the question is can I do this with the built-in commands like mongod, or with a configuration file?
Unlike the HTTP protocol (as used by your web apps running in a web server like Apache), the MongoDB Wire Protocol does not use hostnames when determining how to handle an incoming request. That means there is no equivalent of a host name or virtualhost directive for your MongoDB server.
The MongoDB server configuration file allows you to bind to one or more IP addresses. The bind IP configuration option specifies which IP address(es) the server listens to for incoming connections. For example, this might be: 127.0.0.1 (aka localhost), a comma-delimited list of IP addresses, or all network interfaces if you don't specify a bind IP restriction.
When you connect to MongoDB and specify a hostname in your command line or driver options, this name just has to be resolvable from the external point of view. You can use whatever form of resolvable hostname you want to create outside of MongoDB (for example, in your /etc/hosts file or DNS). As long as the MongoDB server is listening to the IP your hostname resolves to (and there are no firewalls or network connectivity issues), you should be able to connect irrespective of the hostname used.
For example, while localhost is the default name available for the loopback IP address (127.0.0.1) and should always be defined .. normally your computer will also have a unique hostname defined. You can check what your default hostname resolves to in the mongo shell with getHostName():
> getHostName()
Webscale.local
Assuming no bind IP restriction and a hostname of Webscale.local with an IP address of 192.168.1.1, you would be able to connect with any of:
Webscale.local
192.168.1.1
localhost
127.0.0.1
Make use of Docker Environment, create two containers, one for your Mongo Server and another for your App, run both containers inside one docker-compose.yml file, specify that your app container would depend_on your mongo container and then replace "localhost" the connection string in your app with the name of your mongo container. Take reference from the two snippets as below:
docker-compose.yml :
version: '3'
services:
img_flaskapp:
build: ./Flask/gie
container_name: flaskapp
ports:
- "8000:8000"
depends_on:
- img_mongodb
img_mongodb:
image: mongo
container_name: mongodb
ports:
- "27017:27017"
app code:
connect (host="mongodb://mongodb:27017/nameofyourdb")

mongodb client - ssh connection from localhost php

I have been using rockmongo as my client for mongodb on localhost for testing.
For prodction i DONT want a client online as this might reduce security.
Is there a client which will allow me to connect SSH? kind of like MySql Workbench?
or
Can rockmongo stay on my local computer and i connect to EC2 instance which has mongodb for production viewing?
or
Is there a better alternative to all of this?
My setup is a standard LAMP stack. willing to make any changes necessary.
MongoHub has the option to connect over ssh, but the app kind of sucks. It crashes a lot.
A more generic approach would be to just create your own ssh tunnel to your production server, and then connect over that through whatever client you want. The client won't care as long as it can make the connection.
On OSX/Linux, creating an ssh tunnel might look like this:
ssh -L 8080:127.0.0.1:27017 -f -C -q -N username#domain.com
This would open a local port 8080 which will forward the traffic to the localhost interface at the mongodb default port 27017 on the remote side. You would point your client at 127.0.0.1:8080 as if mongodb were running there locally.
Check some of these out - http://www.mongodb.org/display/DOCS/Admin+UIs
One workaround would be to set that file in a separate folder and make a .htaccess file that restricts access to only your ip address. Any requests not from your ip address would get denied access...