How to configure Nginx domain name rewriting and wildcard domain name resolution

How to configure Nginx domain name rewriting and wildcard domain name resolution

This article introduces how to configure Nginx to rewrite domain names and wildcard domain name resolution, and shares it with you. The details are as follows:

#user nobody;
worker_processes 1;
 
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
 
#pid logs/nginx.pid;
 
 
events {
 worker_connections 1024;
}
 
 
http {
 include 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 logs/access.log main;
 
 sendfile on;
 #tcp_nopush on;
 
 #keepalive_timeout 0;
 keepalive_timeout 65;
 
 #gzip on;
 
 #Set the allowed published content to 8M
 client_max_body_size 20M;
 client_body_buffer_size 512k;
 
 add_header Access-Control-Allow-Origin *; 
 add_header Access-Control-Allow-Headers X-Requested-With; 
 add_header Access-Control-Allow-Methods GET,POST,OPTIONS; 
 
 server { 
 listen 80; 
 server_name www.xxx.com; 
 location / { 
 proxy_pass http://127.0.0.1:8080; 
 proxy_set_header Host $host; 
 proxy_set_header X-Real-IP $remote_addr; 
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
 } 
 }
 
 server { 
 listen 80; 
 server_name www.aaa.com; 
 location / { 
 proxy_pass http://127.0.0.1:9989; 
 proxy_set_header Host $host; 
 proxy_set_header X-Real-IP $remote_addr; 
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
 } 
 }
 
 
 #Pan-name resolution server { 
 listen 80; 
 server_name *.web.yuyuyun.cn; 
 location / { 
 # Start configuring wildcard domain name if ( $host ~* (.*)\.(.*)\.(.*)\.(.*) ) {
 set $domain $1; #Get the current domain name prefix}
 proxy_pass http://127.0.0.1:1119/$domain/; 
 proxy_set_header Host $host; 
 proxy_set_header X-Real-IP $remote_addr; 
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
 } 
 
 } 
 
}

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Nginx wildcard domain name resolution configuration tutorial
  • Example tutorial on wildcard domain name configuration in Nginx

<<:  Detailed installation tutorial of mysql 5.7 under CentOS 6 and 7

>>:  4 ways to implement routing transition effects in Vue

Recommend

Simple example of HTML text formatting (detailed explanation)

1. Text formatting: This example demonstrates how...

Example of downloading files with vue+django

Table of contents 1. Overview 2. Django Project 3...

JavaScript implements simple calculator function

This article shares the specific code of JavaScri...

VMware virtual machine three connection methods example analysis

NAT In this way, the virtual machine's networ...

The difference between Div and table in HTML (discussed in detail in all aspects)

1: Differences in speed and loading methods The di...

Example of using javascript to drag and swap div positions

1 Implementation Principle This is done using the...

Five solutions to cross-browser problems (summary)

Brief review: Browser compatibility issues are of...

Two methods to implement MySQL group counting and range aggregation

The first one: normal operation SELECT SUM(ddd) A...

What are Web Slices?

IE8 new feature Web Slices (Web Slices) Microsoft...

Steps for installing MySQL 8.0.16 on Windows and solutions to errors

1. Introduction: I think the changes after mysql8...

Detailed explanation of the role of key in React

Table of contents Question: When the button is cl...

How to successfully retrieve VMware Esxi root password after forgetting it

Prepare a CentOS6 installation disk (any version)...

Solution to the problem that MySQL commands cannot be entered in Chinese

Find the problem Recently, when I connected to th...

HTML table tag tutorial (3): width and height attributes WIDTH, HEIGHT

By default, the width and height of the table are...