Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Virtual Domain name configuration and Test Verification in Linux\ Nginx Environment

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the example analysis of virtual domain name configuration and test verification under Linux\ Nginx environment, which is very detailed and has certain reference value. Interested friends must read it!

With Nginx virtual domain name configuration, you can access the local server through a specific domain name without purchasing a domain name. Reduce unnecessary expenses before release.

Configuration step

1. Edit nginx.conf profile

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

(1) add a domain name to the file name (for future management)

The code added here can be added under the http node of nginx.conf.

But pay attention to the path of the vhost folder, where the path to the created vhost folder is: / usr/local/nginx/Nginx/conf/vhost, but the nginx.conf is in / usr/local/nginx/conf/nginx.conf. You need to pay attention to path settings.

Include vhost/*.conf

(2) Save and exit

Save the exit through the ": wq" command of vim. If you are still editing, you need to press the Esc key before entering the command.

two。 Configure domain name forwarding

(1) create a vhost folder under the installation directory

Mkdir / usr/local/nginx/Nginx/conf/vhost

(2) create and edit domain name forwarding profile

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

Under the vim editor, just copy the following code into it

Server {listen 80; autoindex on; # this is the domain name you want to set up: 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 the access path of Tomcat proxy_pass http://127.0.0.1:8080/; add_header Access-Control-Aloow-Origin *;}}

Save the exit, save the exit through the ": wq" command of vim. If you are still editing, you need to press the Esc key and enter the command.

3. Set hosts settin

The hosts under linux is in / etc/hosts. Just 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# drawing bed 192.168.197.130 iamge.huaiangg.com# front and rear separation server 192.168.197.130 s.huaiangg.com

Save the exit, save the exit through the ": wq" command of vim. If you are still editing, you need to press the Esc key and enter the command.

4. Start (restart) validation

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

(1) start

${nginx} / sbin/nginx

(2) restart

${nginx} / sbin/nginx-s reload

5. Access authentication

Use the default port authentication and modify the default access port in nginx.conf if the port is occupied.

Http://localhost:80

Or

Http://127.0.0.1:80

5. test

You only need to enter the address where the reverse proxy is set in the browser in the Linux environment, such as www.huaiangg.com. For more information, please see:

The above is all the contents of the article "sample Analysis of Virtual Domain name configuration and Test Verification in Linux\ Nginx Environment". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report