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

Will CSS3 really replace SCSS?

When it comes to styling our web pages, we have t...

Tutorial on installing the unpacked version of mysql5.7 on CentOS 7

1. Unzip the mysql compressed package to the /usr...

MySQL8 Installer version graphic tutorial

Installation The required documents are provided ...

MySQL 5.7.27 installation and configuration method graphic tutorial

The installation tutorial of MySQL 5.7.27 is reco...

Analyze MySQL replication and tuning principles and methods

1. Introduction MySQL comes with a replication so...

Detailed explanation of bash command usage

On Linux, bash is adopted as the standard, which ...

Simple example of adding and removing HTML nodes

<br />Simple example of adding and removing ...

Some common mistakes with MySQL null

According to null-values, the value of null in My...

Nginx server https configuration method example

Linux: Linux version 3.10.0-123.9.3.el7.x86_64 Ng...

Summary of a CSS code that makes the entire site gray

In order to express the deep condolences of peopl...

How to implement Mysql scheduled task backup data under Linux

Preface Backup is the basis of disaster recovery....

Detailed steps for manually configuring the IP address in Linux

Table of contents 1. Enter the network card confi...

MySQL executes commands for external sql script files

Table of contents 1. Create a sql script file con...