How to redirect to https through nginx load balancing

How to redirect to https through nginx load balancing

Copy the certificate and key on the web

scp -rp -P52113 /application/nginx/conf/key 10.0.0.5:/application/nginx/conf/

Configuration on nginx load balancing server

vim /application/nginx/conf/nginx.conf

worker_processes 2;
error_log logs/error.log;
events {
  worker_connections 65535;
}
http {
  include mime.types;
  default_type application/octet-stream;
  sendfile on;
  keepalive_timeout 65;
 
 
  upstream server_pools {
    server 10.0.0.200:443 weight=1 max_fails=3 fail_timeout=10;
    #server 10.0.0.8:443 weight=1 max_fails=3 fail_timeout=10;
    #server 10.0.0.9:443 weight=1 max_fails=3 fail_timeout=10;
  }
 
  server {
    listen 80;
    server_name localhost;
    rewrite ^(.*)$ https://$host$1 permanent;
  }
  server {
    listen 10.0.0.5:443;
    server_name www.abc.com;
 
    #Open https. Note that it should be added in the server block. Do not put ssl on in the http block;
    ssl_certificate /application/nginx/conf/key/server.crt;
    ssl_certificate_key /application/nginx/conf/key/server.key;
 
    location / {
      proxy_pass https://server_pools;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $remote_addr;
    }
  }
}

#Check nginx load balancing configuration

/application/nginx/sbin/nginx -t

#Restart nginx load balancing

/application/nginx/sbin/nginx -s stop
/application/nginx/sbin/nginx

Browser access test

Note that the hosts to be modified correspond to the IP address information of the load balancing

Access Test

Visit Results

You may also be interested in:
  • Detailed explanation of the solution for NGINX to jump from https to http
  • How to redirect URL using nginx rewrite
  • How to redirect HTTP 301 to a domain name with www in Nginx server
  • How to force nginx to use https access (http jumps to https)
  • How to configure Nginx page redirection according to different browser languages
  • Detailed explanation of nginx to solve the problem of home page jump
  • Detailed explanation of nginx 301 redirect to domain name with www
  • Solution to nginx not jumping to the upstream address
  • Using Nginx's map command to redirect pages
  • Solve the problem of only redirecting to the home page when deploying thinkPHP 5 with nginx
  • Example code for using Nginx to implement 301 redirect to https root domain name
  • Nginx prohibits direct access via IP and redirects to a custom 500 page
  • Detailed explanation of Nginx rewrite jump application scenarios
  • Detailed explanation of how to enable HSTS in nginx to force the browser to redirect to HTTPS access
  • Implementation of rewrite jump in nginx
  • Detailed explanation of location matching and rewrite redirection in Nginx
  • Nginx hidden redirect (browser URL remains unchanged after redirection)

<<:  Solution to the failure of MySQL to use innobackupex to backup the connection server

>>:  Solution to the Chinese garbled characters problem in MySQL under Ubuntu

Blog    

Recommend

HTML table tag tutorial (24): horizontal alignment attribute of the row ALIGN

In the horizontal direction, you can set the row ...

Detailed explanation of various HTTP return status codes

When a request is sent to your server to display ...

Implementation of mysql configuration SSL certificate login

Table of contents Preface 1. MySQL enables SSL co...

Detailed tutorial on how to create a user in mysql and grant user permissions

Table of contents User Management Create a new us...

Exploration of three underlying mechanisms of React global state management

Table of contents Preface props context state Sum...

Mysql database design three paradigm examples analysis

Three Paradigms 1NF: Fields are inseparable; 2NF:...

Example code of Vue3 encapsulated magnifying glass component

Table of contents Component Infrastructure Purpos...

How to use the Linux more command in Linux common commands

more is one of our most commonly used tools. The ...

How to build your own Nexus private server in Linux

This article describes how to build a Nexus priva...

Solution to nginx-ingress-controller log persistence solution

Recently I saw an article on a public account tha...

Use ab tool to perform API stress test on the server

Table of contents 1 A brief introduction to syste...

How to manually install MySQL 5.7 on CentOS 7.4

MySQL database is widely used, especially for JAV...

Detailed explanation of how to mount remote file systems via SSH on Linux

Features of SSHFS: Based on FUSE (the best usersp...

Complete steps to use element in vue3.0

Preface: Use the element framework in vue3.0, bec...

Detailed explanation of the basic functions and usage of MySQL foreign keys

This article uses examples to illustrate the basi...