Detailed configuration of Nginx supporting both Http and Https

Detailed configuration of Nginx supporting both Http and Https

It is almost a standard feature for websites nowadays to support Https, and Nginx can support the Https function very well. The following is a configuration that supports both Http and Https functions.

It should be noted that since Https is chosen to ensure communication security, there is no need to use Http for communication. The Http method is also supported in the URL, mainly for users who do not know whether the website supports Https or use Http to access it. At this time, the Nginx backend needs to automatically convert the Http request into Https, so that it can support Http and ensure communication security.

Without further ado, here is a configuration of Nginx supporting Http and Https. This is the configuration of my WordPress website supporting Https. You can refer to it.

server
{
  # Enable Https
  listen 443 ssl;
  # Configure the certificate. I won’t go into details about how to apply for a free certificate. Search for Tencent Cloud or Alibaba Cloud free certificate application at night ssl_certificate /etc/nginx/conf.d/cert/4351595_www.xxx.pem;
  ssl_certificate_key /etc/nginx/conf.d/cert/4351595_www.xxx.key;
  ssl_session_timeout 5m;
  ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_prefer_server_ciphers on;
  
  server_name xxx;
  index index.html index.htm index.php;
  root /data/wwwroot/wordpress;
  error_log /var/log/nginx/wordpress-error.log crit;
  access_log /var/log/nginx/wordpress-access.log;

  # This is used to include other configurations include extra/*.conf;
  include conf.d/rewrite/wordpress.conf;

}

# Convert Http request to Https request server {
  listen 80;
  server_name xxx;
  rewrite ^/(.*) https://$server_name$request_uri? permanent;
}

This is the end of this article about the detailed configuration of Nginx supporting both Http and Https. For more relevant configuration content of Nginx supporting both Http and Https, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Example of how to configure nginx to implement SSL
  • Nginx implements https website configuration code example
  • Detailed tutorial on configuring nginx for https encrypted access
  • Implementation of Nginx domain name forwarding https access
  • Alibaba Cloud Nginx configures https to implement domain name access project (graphic tutorial)
  • Detailed explanation of the principle and implementation process of Nginx configuration https
  • Nginx configures the same domain name to support both http and https access
  • Implementation of HTTP and HTTPS services with Nginx reverse proxy for multiple domain names
  • Example code for using Nginx to implement 301 redirect to https root domain name
  • How to change the website accessed by http to https in nginx

<<:  How to gracefully and safely shut down the MySQL process

>>:  How to add Vite support to old Vue projects

Recommend

Detailed explanation of Linx awk introductory tutorial

Awk is an application for processing text files, ...

Detailed explanation of nginx-naxsi whitelist rules

Whitelist rule syntax: BasicRule wl:ID [negative]...

Six ways to reduce the size of Docker images

Since I started working on Vulhub in 2017, I have...

Vue uses canvas handwriting input to recognize Chinese

Effect picture: Preface: Recently, I was working ...

React ref usage examples

Table of contents What is ref How to use ref Plac...

How to understand Vue's simple state management store mode

Table of contents Overview 1. Define store.js 2. ...

An Incomplete Guide to JavaScript Toolchain

Table of contents Overview Static type checking C...

How to set up swap partition SWAP in Linux 7.7

The Swap partition of the Linux system, that is, ...

How to import Chinese data into csv in Navicat for SQLite

This article shares with you the specific method ...

Docker installation and configuration image acceleration implementation

Table of contents Docker version Install Docker E...

HTML Table Tag Tutorial (47): Nested Tables

<br />In the page, typesetting is achieved b...

HTML Marquee character fragment scrolling

The following are its properties: direction Set th...

Reasons for the sudden drop in MySQL performance

Sometimes you may encounter a situation where a S...

MySQL permission control detailed explanation

Table of contents mysql permission control Permis...