← Back to Home

Informatics (My Brain)

A collection of my gists, quick guides, and snippets curated over time.

Nginx Reverse Proxy

March 5, 2020

Nginx Reverse Proxy

Unlink default configs

First, unlink the default configuration which shows Nginx Welcome page on port 80 using the command

path /etc/nginx/sites-enabled

$ sudo unlink default

Add new configs

Create a new .conf file with reverse proxy configuration

path /etc/nginx/conf.d

$ sudo nano sites.conf

Use the following config for each reverse proxy that you want to apply


server {
   listen 80 default_server;
   server_name yourdomain.com www.yourdomain.com;

   location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_pass http://localhost:3000;
   }

}

server {
   listen 80;
   server_name yourdomain.in www.yourdomain.in;

   location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_pass http://localhost:5000;
   }
}

Save Configurations

Now, test your configurations using:

$ sudo nginx -t

Check nginx status to verify that everything is working properly

$ sud...

Run phpMyAdmin On Custom Port

1. Make a virtual host for phpmyadmin

In /etc/apache2/sites-available/ directory create a new file named phpmyadmin.conf

$ sudo nano phpmyadmin.conf

The content of the file should be:

Listen 2222

<VirtualHost *:2222>

        ServerName localhost

        <Directory /usr/share/phpmyadmin>
                AllowOverride None
                Require all granted
        </Directory>

        DocumentRoot /usr/share/phpmyadmin

        Include /etc/phpmyadmin/apache.conf

        ErrorLog ${APACHE_LOG_DIR}/phpmyadmin.error.log
        CustomLog ${APACHE_LOG_DIR}/phpmyadmin.access.log combined

</VirtualHost>

2. Reset apache config and restart server

Disable the /etc/apache2/conf-enabled/phpmyadmin.conf file due to which phpmyadmin is accessible from any domain on apache using the command:

sudo a2disconf phpmyadmin

Now, enable the new config that we create at `/etc/apache2/sites-available/phpmyadmin.c...

Importing a Database

To import a sql database using terminal, use this command:

$ mysql -u username -p -h localhost DATABASE_NAME < file_name.sql

Exporting a Database

To export a database, use the following command:

$ mysqldump -u username -p DATABASE_NAME > file_name.sql

Step 1

SSH into instance using private key or shell provided by the cloud service provider.

Step 2

If you want to create a new user than run

$ sudo adduser username
$ sudo addpasswd username

Step 3

Go to etc/ssh/ and edit sshd_config file.

$ cd /etc/ssh
$ sudo vi sshd_config

Step 4

Set Following as:

PasswordAuthentication yes

If you also want root user to login with password (without private key) set:

PermitRootLogin yes

Step 5

Restart SSH service:

sudo service ssh restart

Step 6

Exit your current session and login using your new credentials.

Protip: If you cant remember your private key use NoIP to get a domain name that you can use to SSH.

Install MongoDB on Ubuntu

Step by step guide to install MongoDB on Ubuntu.

1 > Installing MongoDB

First update the packages

$ sudo apt-get update

install the MongoDB package

$ sudo apt install -y mongodb

2 > Checking the Service and Database

$ sudo systemctl status mongodb

You should see something like this:

● mongodb.service - An object/document-oriented database
   Loaded: loaded (/lib/systemd/system/mongodb.service; disabled; vendor preset:
   Active: active (running) since Mon 2019-06-17 20:20:39 IST; 6s ago
     Docs: man:mongod(1)
 Main PID: 28176 (mongod)
    Tasks: 23 (limit: 4915)
   CGroup: /system.slice/mongodb.service
           └─28176 /usr/bin/mongod --unixSocketPrefix=/run/mongodb --config /etc

3 > Managing the MongoDB Service

To know the status of the MongoDB, use:

$ sudo systemctl status mongodb

To stop the MongoDB server, use:

$ sudo systemctl stop mongodb

To start...

Installing LAMP server on Linux

Step by step guide to install LAMP server on Linux.

Installation

Use the terminal to execute these commands

Install Apache

sudo apt install apache2

Install MySQL

sudo apt install mysql-server

After installation run this command to remove some dangerous defaults and lock down access to your database system.

sudo mysql_secure_installation

This will ask if you want to configure the VALIDATE PASSWORD PLUGIN.

Answer Y for yes, or anything else to continue without enabling.

Remove anonymous users? : Y

Disallow root login remotely? : Y

Remove test database and access to it? : Y

Reload privilege tables now? : Y

Now enter mysql

sudo mysql

View all user accounts using

mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;

Now, to set a new password for root user, replace 'password' with your own password.