Virtual domain name configuration and test verification under Linux\Nginx environment

Virtual domain name configuration and test verification under Linux\Nginx environment

By using Nginx virtual domain name configuration, you can access the local server through a specific domain name without purchasing a domain name. Reduce unnecessary pre-launch expenses.

Configuration steps

1. Edit the nginx.conf configuration file

sudo vim /usr/local/nginx/Nginx/conf/nginx.xonf

(1) Add the domain name to the file name (for easy management in the future)

The following code is added under the http node of nginx.conf.

But you need to pay attention to the path of the vhost folder. The path of the vhost folder created here is: /usr/local/nginx/Nginx/conf/vhost, but nginx.conf is in /usr/local/nginx/conf/nginx.conf. Pay attention to the path setting.

include vhost/*.conf

(2) Save and exit

Use vim's ":wq" command to save and exit. If you are still in editing mode, you need to press the Esc key first and then enter the command.

2. Configure domain name forwarding

(1) Create a vhost folder in the installation directory

mkdir /usr/local/nginx/Nginx/conf/vhost

(2) Create and edit domain forwarding configuration files

# www.huaiangg.com is the domain name you want to customize, add the suffix .vonf and you can vim /usr/local/nginx/Nginx/conf/vhost/www.huaiangg.com.conf

In the vim editor, copy the following code into it.

server {
  listen 80;
  autoindex on;
  # This is the domain name you want to set server_name www.huaiangg.com;
  access_log /usr/local/nginx/logs/access.log combined;
  index index.html index.htm index.jsp index.php;
  #error_page 404 /404.html;
  if ( $query_string ~* ".*[\;'\<\>].*" ){
    return 404;
  }
  location / {
    # Here, set the reverse proxy to Tomcat's access path proxy_pass http://127.0.0.1:8080/;
    add_header Access-Control-Aloow-Origin *;
  }
}

Save and exit. Use vim's ":wq" command to save and exit. If you are still in editing mode, you need to press the Esc key and then enter the command.

3. Set hosts settings

The hosts under Linux are in /etc/hosts. Use vim to open the corresponding path.

vim /etc/hosts

Configure related domain names

#centos
# Reverse proxy--> tomcat address 192.168.197.130 www.huaiangg.com
# Image hosting 192.168.197.130 iamge.huaiangg.com
# Front-end and back-end separation server 192.168.197.130 s.huaiangg.com

Save and exit. Use vim's ":wq" command to save and exit. If you are still in editing mode, you need to press the Esc key and then enter the command.

4. Start (restart) verification

Note: ${nginx} represents the default installation path of the system, for example: /usr/local/nginx/

(1) Start

${nginx}/sbin/nginx

(2) Restart

${nginx}/sbin/nginx -s reload

5. Access Verification

Use the default port for authentication. If the port is occupied, modify the default access port in nginx.conf.

http://localhost:80

or

http://127.0.0.1:80

5. Testing

Just enter the address of the reverse proxy in the browser in the Linux environment, for example: www.huaiangg.com, see below for details:

Summarize

The above is the virtual domain name configuration and test verification under the Linux\Nginx environment introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Springboot+nginx+https+linux to achieve load balancing and domain name access simple test
  • Detailed explanation of how to configure multiple domain names in Nginx on Alibaba Cloud Linux system
  • How to configure multiple domain names on one nginx server
  • Detailed explanation of nginx listening to multiple domain names on the same port and listening to http and https at the same time
  • Example of configuring personalized secondary domain names and multiple domain names under Nginx server
  • Nginx configuration example for distributing content based on domain name http and https
  • Example of 301 redirection configuration for domain names and directories in nginx

<<:  Does MySql need to commit?

>>:  Detailed explanation of JavaScript closure issues

Recommend

What is the function and writing order of the a tag pseudo class

The role of the a tag pseudo-class: ":link&qu...

How to use the markdown editor component in Vue3

Table of contents Install Importing components Ba...

How to set a fixed IP address in CentOS7 virtual machine

Since my development environment is to install Ce...

Introduction to HTML method of opening link files using hyperlinks

a and href attributes HTML uses <a> to repr...

Sample code for implementing history in vuex

I have recently been developing a visual operatio...

From CSS 3D to spatial coordinate axis with source code

One time we talked about the dice rolling game. A...

Regarding the Chinese garbled characters in a href parameter transfer

When href is needed to pass parameters, and the p...

CSS implements 0.5px lines to solve mobile compatibility issues (recommended)

【content】: 1. Use background-image gradient style...

HTML Grammar Encyclopedia_HTML Language Grammar Encyclopedia (Must Read)

Volume Label, Property Name, Description 002 <...

W3C Tutorial (10): W3C XQuery Activities

XQuery is a language for extracting data from XML...

Split and merge tables in HTML (colspan, rowspan)

The code demonstrates horizontal merging: <!DO...

How to batch generate MySQL non-duplicate mobile phone number table example code

Preface In many MySQL test scenarios, some test d...

Vue implements a visual drag page editor

Table of contents Drag and drop implementation Dr...

Memcached method for building cache server

Preface Many web applications store data in a rel...