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

How to use lodop print control in Vue to achieve browser compatible printing

Preface This control will have a watermark at the...

Installation steps of mysql under linux

1. Download the mysql tar file: https://dev.mysql...

Let IE6, IE7, IE8 support CSS3 rounded corners and shadow styles

I want to make a page using CSS3 rounded corners ...

Teach you how to use webpack to package and compile TypeScript code

TypeScript Bundling webpack integration Usually, ...

The viewport in the meta tag controls the device screen css

Copy code The code is as follows: <meta name=&...

Detailed explanation of JavaScript timers

Table of contents Brief Introduction setInterval ...

Simple example of limit parameter of mysql paging

Two parameters of Mysql paging select * from user...

Disable autocomplete in html so it doesn't show history

The input box always displays the input history wh...

Example to explain the size of MySQL statistics table

Counting the size of each table in each database ...

How to implement second-level scheduled tasks with Linux Crontab Shell script

1. Write Shell script crontab.sh #!/bin/bash step...

How to clear the validation prompt in element form validation

Table of contents Problem scenario: Solution: 1. ...

WeChat applet implements jigsaw puzzle game

This article shares the specific code for impleme...