Implementation of HTTP and HTTPS services with Nginx reverse proxy for multiple domain names

Implementation of HTTP and HTTPS services with Nginx reverse proxy for multiple domain names

Currently, Nginx has reverse proxyed two websites, namely Windows-based IIS and Linux-based Apache server, to provide web services.

Now there is a new project web page that needs to provide services to the outside world. It is necessary to add another website on the proxy server, use HTTPS access and automatically jump from HTTP to HTTPS. Since the new web page is a static page, it is deployed on the Nginx proxy server using Docker. The relevant certificates are obtained through Let's Encrypt. They are all separate certificates, and no wildcard certificates are applied for.

You only need to deploy an SSL certificate on the Nginx proxy side. You can also implement HTTPS access without deploying SSL on the backend.

Nginx proxy server configuration:

worker_processes auto;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
 worker_connections 1024;
}

http {
 include /usr/local/nginx/conf/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;
 tcp_nodelay on;

upstream dx.exzel.co.nz {

 server 127.0.0.1:8080;
}

upstream mybusiness.exzel.co.nz {

 server 192.168.1.252:443;
}

server {
 listen 80;
 server_name dx.exzel.co.nz;
 rewrite ^(.*) https://dx.exzel.co.nz permanent;
}
server {
 listen 443;
 server_name dx.exzel.co.nz;
 ssl on;
 ssl_certificate /etc/letsencrypt/live/dx.exzel.co.nz/fullchain.pem;
 ssl_certificate_key /etc/letsencrypt/live/dx.exzel.co.nz/privkey.pem;
 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;
 access_log /var/log/nginx/ccieerror.log ;
 location / {
   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_pass http://dx.exzel.co.nz;

 }
}

server {
 listen 80;
 server_name mybusiness.exzel.co.nz;
 rewrite ^(.*) https://mybusiness.exzel.co.nz permanent;
}
server {
 listen 443;
 server_name mybusiness.exzel.co.nz;
 ssl on;
 ssl_certificate /etc/letsencrypt/live/mybusiness.exzel.co.nz/fullchain.pem;
 ssl_certificate_key /etc/letsencrypt/live/mybusiness.exzel.co.nz/privkey.pem;
 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;
 access_log /var/log/nginx/mybusiness.log ;
 location / {
   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_pass https://mybusiness.exzel.co.nz;

 }
}

server {
 listen 80;
 server_name www.empnz.co.nz empnz.co.nz;
  location / {
    proxy_pass http://192.168.1.15 ;
    }
 }

}

This is the end of this article about the implementation of HTTP and HTTPS services for multiple domain names with Nginx reverse proxy. For more relevant content about Nginx reverse proxy HTTP and HTTPS, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Two ways to implement nginx https reverse proxy tomcat
  • Nginx server https configuration method example
  • Detailed explanation of the correct way to redirect nginx server http to https
  • Nginx build https server tutorial
  • Detailed explanation of configuring HTTPS (NGINX) on Alibaba Cloud LINUX server
  • How to build HTTPS server with Nginx and force HTTPS access
  • Problems with configuring https server and reverse proxy with Nginx under Windows

<<:  Examples of preview functions for various types of files in vue3

>>:  Examples of correct use of maps in WeChat mini programs

Recommend

Detailed explanation of JS variable storage deep copy and shallow copy

Table of contents Variable type and storage space...

Div css naming standards css class naming rules (in line with SEO standards)

There are many tasks to be done in search engine o...

JavaScript history object explained

Table of contents 1. Route navigation 2. History ...

Detailed explanation of the 4 codes that turn the website black, white and gray

The 2008.5.12 Wenchuan earthquake in Sichuan took...

An example of refactoring a jigsaw puzzle game using vue3

Preface It took two days to reconstruct a puzzle ...

Example of Vue routing listening to dynamically load the same page

Table of contents Scenario Analysis Development S...

MySQL uses custom sequences to implement row_number functions (detailed steps)

After reading some articles, I finally figured ou...

Detailed explanation of how to use the calendar plugin implemented in Vue.js

The function to be implemented today is the follo...

Why does your height:100% not work?

Why doesn't your height:100% work? This knowl...

mysql error number 1129 solution

SQLyog connects to mysql error number 1129: mysql...

In-depth understanding of javascript prototype and prototype chain

Table of contents 1. What is a prototype? 2. Prot...

In-depth understanding of Worker threads in Node.js

Table of contents Overview The history of CPU-bou...

Two common solutions to html text overflow display ellipsis characters

Method 1: Use CSS overflow omission to solve The ...

Five ways to traverse JavaScript arrays

Table of contents 1. for loop: basic and simple 2...