Showing posts with label Nginx. Show all posts
Showing posts with label Nginx. Show all posts

Monday, February 20, 2023

How to Install Nginx, MariaDB, PHP and Create Virtual Server Block with Nginx on AlmaLinux 8

yum install nginx -y
systemctl start nginx
systemctl enable nginx
systemctl status nginx
nginx -v


firewall-cmd --permanent --zone=public --add-service=http 
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
chown nginx:nginx /usr/share/nginx/html -R

################ MariaDB ##############################

yum install mariadb-server mariadb -y
systemctl start mariadb
systemctl enable mariadb
systemctl status mariadb
mysql_secure_installation
mysql -e "SHOW DATABASES;" -p

################ PHP installation ##########################

yum install php php-mysqlnd php-fpm php-opcache php-gd php-xml php-mbstring php-json -y

################### For Specific PHP Version #################
sudo dnf config-manager --set-enabled crb
sudo dnf install epel-release -y
sudo dnf install http://rpms.remirepo.net/enterprise/remi-release-9.rpm
sudo dnf update -y
sudo dnf module list php
sudo dnf -y install yum-utils
sudo dnf module enable php:remi-8.2 -y
########################################################
systemctl start php-fpm

systemctl enable php-fpm

systemctl status php-fpm

vi /etc/php-fpm.d/www.conf

user = nginx
group = nginx

systemctl reload php-fpm

echo "<?php phpinfo() ?>" > /usr/share/nginx/html/info.php

systemctl restart nginx php-fpm
########################################################
            Host File
=====================================================
sudo vi /etc/hosts
IP_ADDRESS mt.baycombd.com
chown nginx:nginx /var/www/example.com/public_html -R
echo "<?php phpinfo() ?>" > /var/www/example.com/public_html/info.php
======================================================
         Custom  Public_html Directory
=====================================================
sudo mkdir -p /var/www/example.com/public_html
sudo chown -R nginx:nginx /var/www/example.com/public_html
sudo chmod -R +x /var/www
sudo chcon -t httpd_sys_content_t /var/www/example.com -R
sudo chcon -t httpd_sys_rw_content_t /var/www/example.com -R
=====================================================
             Create Custom Server Block 
=====================================================
touch /etc/nginx/conf.d/example.com.conf
# Web root location & port listining
server 
{
        listen 80;
        root /var/www/example.com/public_html;
        index index.php index.html index.htm;
        server_name example.com www.example.com;
        access_log /var/www/example.com/access.log;
        error_log /var/www/example.com/error.log;

# Redirect server error pages to the static page
        location / 
{
try_files $uri $uri/ /index.php;
        }
        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        location = /50x.html 
{
        root /var/www/example.com/public_html;
        }
# Pass the PHP scripts to FastCGI server
location ~ \.php$ 
{
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        try_files $uri =404;
       # fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php-fpm/www.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_index index.php;
        include fastcgi_params;
        }
}      
======================================================
systemctl restart nginx php-fpm
nginx -t

Tuesday, October 25, 2022

Nginx server block configuration for MailWizz

 server {

  #    if ($host = www.yourdomain.com) {

  #     return 301 https://$host$request_uri;

  #  } # managed by Certbot


    root /var/www/yourdomain.com/public/;

    server_name yourdomain.com www.yourdomain.com;

  # Add index.php to setup Nginx, PHP & PHP-FPM config

  # index index.php index.html index.htm index.nginx-debian.html;


    listen [::]:443 ssl ipv6only=on; # managed by Certbot

    listen 443 ssl; # managed by Certbot

    ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem; # managed by Certbot

    ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem; # managed by Certbot


#   ssl_certificate /etc/letsencrypt/live/www.yourdomain.com/fullchain.pem; # managed by Certbot

#    ssl_certificate_key /etc/letsencrypt/live/www.yourdomain.com/privkey.pem; # managed by Certbot

    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot

    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


  location / {

    #try_files $uri $uri/ =404;

         if (!-e $request_filename){

             rewrite ^(/)?api/.*$ /api/index.php;

         }

         if (!-e $request_filename){

             rewrite ^(/)?customer/.*$ /customer/index.php;

         }

         if (!-e $request_filename){

             rewrite ^(/)?backend/.*$ /backend/index.php;

         }

         if (!-e $request_filename){

             rewrite ^(.*)$ /index.php;

         }

         index  index.html index.htm index.php;

   }


  # pass PHP scripts on Nginx to FastCGI (PHP-FPM) server

  location ~ \.php$ {

    include snippets/fastcgi-php.conf;

    include /etc/nginx/fastcgi_params;

    # fastcgi_pass  127.0.0.1:9000;

    # fastcgi_index index.php;

    #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    #fastcgi_read_timeout 600s;

    #fastcgi_send_timeout 600s;

    # Nginx php-fpm sock config:

    fastcgi_pass unix:/run/php/php8.1-fpm.sock; #For PHP-FPM

    # Nginx php-cgi config :

    # Nginx PHP fastcgi_pass 127.0.0.1:9000;

  }


  # deny access to Apache .htaccess on Nginx with PHP, 

  # if Apache and Nginx document roots concur

  location ~ /\.ht {

    deny all;

  }

}

Monday, October 24, 2022

Nginx server basic configuration for MailWizz

/etc/nginx/nginx.conf

# For more information on configuration, see:

#   * Official English Documentation: http://nginx.org/en/docs/

#   * Official Russian Documentation: http://nginx.org/ru/docs/


user  nginx;

worker_processes  1;


error_log  /var/log/nginx/error.log;

#error_log  /var/log/nginx/error.log  notice;

#error_log  /var/log/nginx/error.log  info;


pid        /run/nginx.pid;



events {

    worker_connections  1024;

}



http {

    include       /etc/nginx/mime.types;

    default_type  application/octet-stream;


    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';


    access_log  /var/log/nginx/access.log  main;


    sendfile        on;

    #tcp_nopush     on;


    #keepalive_timeout  0;

    keepalive_timeout  65;


    #gzip  on;


    # Load modular configuration files from the /etc/nginx/conf.d directory.

    # See http://nginx.org/en/docs/ngx_core_module.html#include

    # for more information.

    include /etc/nginx/conf.d/*.conf;


    index   index.html index.htm;


    #root /usr/share/nginx/html;


  # this is the section that matters for mailwizz.

    server {

     listen      80;

     server_name domain.com;

     root        /usr/share/nginx/html;


     location / {

         if (!-e $request_filename){

             rewrite ^(/)?api/.*$ /api/index.php;

         }

         if (!-e $request_filename){

             rewrite ^(/)?customer/.*$ /customer/index.php;

         }

         if (!-e $request_filename){

             rewrite ^(/)?backend/.*$ /backend/index.php;

         }

         if (!-e $request_filename){

             rewrite ^(.*)$ /index.php;

         }

         index  index.html index.htm index.php;

     }


     #error_page  404              /404.html;


     # redirect server error pages to the static page /50x.html

     #

     error_page   500 502 503 504  /50x.html;


     # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

     #

     location ~ \.php$ {

        include /etc/nginx/fastcgi_params;

        fastcgi_pass  127.0.0.1:9000;

        fastcgi_index index.php;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;


        fastcgi_read_timeout 600s;

        fastcgi_send_timeout 600s;

    }


     # deny access to .htaccess files, if Apache's document root

     # concurs with nginx's one

     #

     location ~ /\.ht {

         deny  all;

     }

   }

}

Friday, October 21, 2022

Installing PHP 8.1 to Add PHP support to Nginx on Ubuntu

 Install PHP for Nginx with PHP-FPM:

sudo apt update

sudo apt install --no-install-recommends php8.1 [Apache HTTP server and its httpd process]

sudo apt-get install php8.1-fpm -y [For PHP-FPM works with nginx]

php -v

sudo apt-get install -y php8.1-cli php8.1-common php8.1-mysql php8.1-zip php8.1-gd php8.1-mbstring php8.1-curl php8.1-xml php8.1-bcmath php8.1-imap

php -m


Check if PHP-FPM is running:

sudo systemctl status php8.1-fpm

Add PHP support to Nginx:

sudo nano /etc/nginx/sites-available/default

Enable PHP in Nginx’s config file:

server {

  # Example PHP Nginx FPM config file

  listen 80 default_server;

  listen [::]:80 default_server;

  root /var/www/html;

  # Add index.php to setup Nginx, PHP & PHP-FPM config

  index index.php index.html index.htm index.nginx-debian.html;

  server_name _;

  location / {

    try_files $uri $uri/ =404;

  }

  # pass PHP scripts on Nginx to FastCGI (PHP-FPM) server

  location ~ \.php$ {

    include snippets/fastcgi-php.conf;


    # Nginx php-fpm sock config:

    fastcgi_pass unix:/run/php/php8.1-fpm.sock;

    # Nginx php-cgi config :

    # Nginx PHP fastcgi_pass 127.0.0.1:9000;

  }

  # deny access to Apache .htaccess on Nginx with PHP, 

  # if Apache and Nginx document roots concur

  location ~ /\.ht {

    deny all;

  }

} # End of PHP FPM Nginx config example

sudo nginx -t

sudo systemctl restart nginx

How to install MySQL on Ubuntu 22.04

 Installing MySQL:

sudo apt update

sudo apt install mysql-server

sudo systemctl start mysql.service


Configuring MySQL:

sudo mysql_secure_installation



Creating a Dedicated MySQL User and Granting Privileges:

  sudo mysql

 mysql -u root -p

 CREATE USER 'mailapp'@'localhost' IDENTIFIED WITH authentication_plugin BY 'password';

 CREATE USER 'mailapp'@'localhost' IDENTIFIED BY 'password';

 CREATE USER 'mailapp'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

 ALTER USER 'mailapp'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

 GRANT CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT on *.* TO 'mailapp'@'localhost' WITH GRANT OPTION;

 GRANT ALL PRIVILEGES ON *.* TO 'mailapp'@'localhost' WITH GRANT OPTION;

 FLUSH PRIVILEGES;

 exit

 

 mysql -u mailapp -p

How To Make secured Nginx with Let's Encrypt on Ubuntu

 Installing Certbot:

sudo apt install certbot python3-certbot-nginx

Confirming Nginx’s Configuration:

sudo nano /etc/nginx/sites-available/example.com

sudo nginx -t

sudo systemctl reload 


Allowing HTTPS Through the Firewall:

sudo ufw status

sudo ufw allow 'Nginx Full'

sudo ufw delete allow 'Nginx HTTP'

sudo ufw status


Obtaining an SSL Certificate:

sudo certbot --nginx -d example.com -d www.example.com



 Verifying Certbot Auto-Renewal:

 sudo systemctl status certbot.timer

 sudo certbot renew --dry-run

Monday, August 29, 2022

How to install NGINX and configure on Ubuntu 20.04

sudo apt-get update

sudo apt upgrade

sudo apt install nginx

sudo systemctl status nginx

sudo ufw allow http

sudo ufw reload


sudo systemctl status nginx

sudo systemctl stop nginx

sudo systemctl start nginx


sudo systemctl disable nginx

sudo systemctl enable nginx

sudo systemctl restart nginx

sudo systemctl reload nginx



sudo unlink /etc/nginx/sites-enabled/default

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

sudo nginx -t

sudo systemctl restart nginx

sudo mkdir /var/www/example.com

Sunday, August 28, 2022

How To Set Up Nginx Virtual Hosts Server Blocks on Ubuntu 20.04

Follow the steps to Set Up Nginx Virtual Hosts Server Blocks on Ubuntu 20.04:


 1. Create New Document Root Directory


sudo mkdir -p /var/www/yourdomain.com/public

sudo chown -R $USER:$USER /var/www/yourdomain.com/public

sudo chmod -R 755 /var/www


2. Creating Pages

nano /var/www/yourdomain.com/public/index.html



3.Creating new site available or server block copied from existing/default domain:

sudo cp /etc/nginx/sites-available/defaultdomain.com /etc/nginx/sites-available/yourdomain.com


4.  Enabling  Server Blocks and Restart Nginx

sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/


5. Restart Nginx

sudo nginx -t

sudo systemctl restart nginx


6. Modify Local hosts file (optional)

sudo nano /etc/hosts


203.0.113.5 yourdomain.com www.yourdomain.com


7. Test website

https://easy2move.fr


Extract Domain from email in Excel or Google sheet

  =TEXTAFTER( A2 , "@") or, =MID(A1, FIND("@", A1) + 1, LEN(A1) - FIND("@", A1))