Saturday, May 9, 2020

nginx master configration

cd /etc/nginx/nginx.conf 
cd /etc/nginx/config.d
cd /usr/share/nginx/html # default log file and defal nginx login file
cd /etc/nginx/nginx.conf.d


server {
    listen 80;
    server_name amit.com;
    location / {
        root /var/www/html;
        index index.html index.htm;
        access_log /var/www/html/access.log main;
        error_log /var/www/html/error.log;

        error_page 404 /404.html;
        location = /40x.html {
          root /var/www/html/india;

        }
    }
}

====================================================

dashboard.amit.com to Redirect project.mukesh.com
server {
  #  listen 80;
    server_name dashboard.amit.com;
     location / {
                 proxy_pass http://project.mukesh.com;
            proxy_set_header Host $http_host;
}
   }

+++++++++++++++++
## Generate ssl certifcate

 openssl genrsa -des3 -out india.amit.com.key 1024 #Generate key
openssl req -new -key india.amit.com.key -out india.amit.com.csr #Generate csr
cp india.amit.com.org india.amit.com.key.org # unprotect key
openssl rsa -in india.amit.com.key.org -out india.amit.com.key #  writing RSA key

 openssl x509 -req -days 365 -in india.amit.com.csr -signkey india.amit.com.key -out india.amit.com.crt  # Getting Private key


server {
    listen 80;
    listen 443;
    ssl on;
    ssl_certificate /etc/nginx/conf.d/india.amit.com.crt  ;
    ssl_certificate_key /etc/nginx/conf.d/india.amit.com.key;
    server_name amit.com;
    location / {
        root /var/www/html;
        index index.html index.htm;
        access_log /var/www/html/access.log main;
        error_log /var/www/html/error.log;

        error_page 404 /404.html;
        location = /40x.html {
          root /var/www/html/india;

        }
    }
}


==================================load Balancer=============
upstream prod_backend {
  least_conn;
  server 192.168.1.10 max_fails=3 fail_timeout=60s;
  server 192.168.1.10 max_fails=3 fail_timeout=60s;
}
server {
  listen 80;
  location / {
    proxy_set_header Host          $host;
    client_max_body_size           120m;
    client_max_body_buffer_size    120k;
    proxy_connect_timeout           120s;
    proxy_send_timeout             120s;
    proxy_read_timeout              120s;
    proxy_pass http://prod_backend;
  }
}
}

=======================revorce proxy================================

server {
  listen 80;
  server_name india.amit.com;
}


  location/ {
    proxy_pass http://127.0.0.1:3000;
    proxy_http_version  1.1;
    proxy_cache_bypass  $http_upgrade;

   # proxy_set_header Upgrade           $http_upgrade;
   # proxy_set_header Connection        "upgrade";
    proxy_set_header Host              $host;
    proxy_set_header X-Real-IP         $remote_addr;
    proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
   # proxy_set_header X-Forwarded-Host  $host;
   # proxy_set_header X-Forwarded-Port  $server_port;
  }


###################### tomcat redirect to nginx===============
server {
  server_name blog.amit.com;
  rewrite ^/(.*)$/department2/$1;   # for only redirect website
  location /{
    proxy_pass http://127.0.0.1:8282;

  }
}

No comments:

Post a Comment