Skip to content

Instantly share code, notes, and snippets.

@majidalaeinia
Created January 22, 2022 18:36
Show Gist options
  • Save majidalaeinia/4f00c39a7a31a370fa8afb561ef4c6ae to your computer and use it in GitHub Desktop.
Save majidalaeinia/4f00c39a7a31a370fa8afb561ef4c6ae to your computer and use it in GitHub Desktop.
nginx.md

Nginx

Global Context

// nginx.conf
http {
    upstream {
    }
    server {
        location {
        }
    }
}

Curl multiple times from the terminal

for i in {1..10}; do curl localhost/images/ > /dev/null; done

Basic Authentication

htpasswd -c /etc/nginx/passwords admin // create a new password for user `admin`
htpasswd /etc/nginx/passwords user1 // set new password for user `user1`
htpasswd -D /etc/nginx/passwords user2 // delete user `user2` user and pass

Troubleshooting

sudo lsof -P -n -i :80 -i :443 | grep LISTEN
sudo netstat -plan | grep nginx
tail -f /var/log/nginx/*.log
systemctl status nginx mysqld php7.2-fpm | grep -E "Loaded|Active"

Install MariaDB

apt install mariadb-server mariadb-client

systemctl status mysqld.service
mysql --version

mysql_secure_installation
mysql -u root -p
CREATE DATABASE IF NOT EXISTS appointments;
CREATE USER IF NOT EXISTS 'admin';
grant all on appointments.* to 'admin'@'localhost' identified by 'password';
mysql -u admin -p
show databases;
use appointments;
show tables;

SSL

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx.key -out /etc/ssl/certs/nginx.crt
@majidalaeinia
Copy link
Author

Nginx location match tester
https://nginx.viraptor.info/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment