Linux \ Nginx virtual domain configuration and verification test

Use Nginx virtual domain configuration, you can not go to purchase a domain name, you can access the local server through a specific domain name. Reduce unnecessary expenses before posting.

Configuration Steps

1. Edit profile nginx.conf

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

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

  • The code can be added here is added at http junction of nginx.conf.
  • But the path to note vhost folder path here vhost created folder is: / usr / local / nginx / Nginx / conf / vhost, but nginx.conf in / usr / local / nginx / conf / nginx. conf. Note path settings.
include vhost/*.conf

(2) save and exit

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

2. Configure Domain Forwarding

(1) Create a folder in vhost installation directory

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

(2) create a configuration file editing domain forwarding

# www.huaiangg.com 为你想要自定义的域名,加上后缀 .vonf 便可
vim /usr/local/nginx/Nginx/conf/vhost/www.huaiangg.com.conf
  • In vim editor, copy the following code into the can
server {
    listen 80;
    autoindex on;
    # 这是你想要设置域名
    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 / {
        # 这里把反向代理设置成 Tomcat 的访问路径
        proxy_pass http://127.0.0.1:8080/;
        add_header Access-Control-Aloow-Origin *;
    }
}
  • Save and exit through the vim: save and exit "wq" command. If it is in edit mode, need to press the Esc key, and then enter the command.

    3. Set the hosts set

  • linux hosts under the / etc / hosts, open the respective paths can be used vim
vim /etc/hosts
  • Configuration related domain names
#centos
# 反向代理 --> tomcat 地址
192.168.197.130 www.huaiangg.com
# 图床
192.168.197.130 iamge.huaiangg.com
# 前后端分离服务器
192.168.197.130 s.huaiangg.com
  
  • Save and exit through the vim: save and exit "wq" command. If it is in edit mode, need to press the Esc key, and then enter the command.

4. (re) started verification

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

(1) Start

${nginx}/sbin/nginx

(2) Restart

${nginx}/sbin/nginx -s reload

5. Verify access

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

http://localhost:80

or

http://127.0.0.1:80

5. Test

  • Only in the Linux environment, set the input reverse proxy address in the browser can be, for example: www.huaiangg.com, detailed below:

www.huaiangg.com


If a man unknown to concentrate fall asleep!
Like a friend you can leave your praise!

Guess you like

Origin www.cnblogs.com/huaiangg/p/11940699.html