With Nginx virtual domain configuration, you can access the local server through a specific domain name without having to purchase a domain name. Reduce unnecessary pre-launch expenses.

The configuration steps

1. Edit the nginx.conf configuration file

 sudo vim /usr/local/nginx/Nginx/conf/nginx.xonfCopy the code

(1) Add the domain name to the file name (easy to manage later)

  • The following code is added to the HTTP node of nginx.conf.
  • The path of the vhost folder is as follows: / usr/local/nginx/nginx/conf/vhost, but nginx. Conf in/usr/local/nginx/conf/nginx. Conf. Pay attention to path Settings.
include vhost/*.confCopy the code

(2) Save and exit

Run the “:wq” command on vim to save the configuration and exit. If you are in editing mode, press Esc and then run the command.

2. Configure domain name forwarding

(1) Create a vhost folder in the installation directory

 mkdir /usr/local/nginx/Nginx/conf/vhostCopy the code

(2) Create and edit the domain name forwarding configuration file

# www.huaiangg.com for a custom domain name you want, the suffix. Vonf can vim/usr/local/nginx/Nginx/conf/vhost/www.huaiangg.com.confCopy the code
  • 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 / {# set the reverse proxy to proxy_pass http://127.0.0.1:8080/; add_header Access-Control-Aloow-Origin *; }}Copy the code
  • Save the configuration and exit. Run the “:wq” command on vim to save the configuration and exit. If you are still in editing mode, press Esc and then run the command.

3. Set hosts Settings

  • In Linux, hosts is stored in /etc/hosts. Use vim to open the corresponding directory
vim /etc/hostsCopy the code
  • Configuring Domain Names
#centos # reverse proxy --> Tomcat address 192.168.197.130 www.huaiangg.com # map bed 192.168.197.130 iamge.huaiangg.com 192.168.197.130 s.huaiangg.comCopy the code
  • Save the configuration and exit. Run the “:wq” command on vim to save the configuration and exit. If you are still in editing mode, press Esc and then run the command.

4. Enable or restart the authentication

  • Note: ${nginx} represents the default installation path, such as /usr/local/nginx/

(1)

${nginx}/sbin/nginxCopy the code

(2) restart

${nginx}/sbin/nginx -s reloadCopy the code

5. Access authentication

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

http://localhost:80Copy the code

or

http://127.0.0.1:80Copy the code

5. Test

  • In Linux, enter the reverse proxy address in the browser, for example, www.huaiangg.com. For details, see the following:

If unknown, concentrate on sword training!

Like friends can leave your praise!