Nginx configuration domain name access

1. For the locally developed demo program, under the target directory, type all the files of META-INF, WEB-INF, index.jsp into a zip package, as shown in the figure below:

 

2. Under the Linux server, deploy to Tomcat, clear all files in the ROOT directory, put the nginx.zip file in 1 in the ROOT directory, after decompression, switch to

In the Tomcat bin directory, start Tomcat. Turn off the firewall, the outside can be accessed through port: IP.

 
  1. # 解压

  2. [root@localhost ROOT]# unzip nginx.zip

  3. [root@localhost ROOT]# /opt/apache-tomcat-8.5.34/webapps/ROOT

  4. [root@localhost ROOT]# ls

  5. index.jsp META-INF nginx.zip WEB-INF

  6. # bin下 启动Tomcat

  7. [root@localhost bin]# ./startup.sh

3. Install nginx, refer to   nginx installation configuration

    Installation directory: /usr/local/nginx

4. Configure nginx for domain name access

 
  1. [root@localhost conf]# pwd

  2. /usr/local/nginx/conf

  3. [root@localhost conf]# cat -n nginx.conf

5. Attach the main configuration code configuration

 #gzip  on;
    	
    	    upstream testnginx{
    	      server localhost:8080;
    	      #server localhost:8081;
    	    }
    	    server {
    	        listen       80;
    	        server_name  www.testnginx.com;
    	
    	        #charset koi8-r;
    	
    	        #access_log  logs/host.access.log  main;
    
    	        location / {
    	            proxy_pass http://testnginx;
    	             #proxy_pass http://localhost:8080;
    	            #proxy_set_header Host $http_host;
    	            #proxy_set_header X-Real-IP $remote_addr;
    	            #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    	            #index  index.html index.htm;
    	        }
    	
    	        #error_page  404              /404.html;

6. Modify the configuration and reload nginx

 
  1. [root@localhost sbin]# pwd

  2. /usr/local/nginx/sbin

  3. [root@localhost sbin]# ./nginx -s reload

7. Because there is no unified DNS settings (generally companies have, you can do unified resolution), so you need to modify the local host file as follows to do domain name IP mapping. Because the DNS of the external network cannot resolve the domain name www.testnginx.com configured by nginx above, it cannot be requested. The host configuration is as follows:

 
  1. host路径: C:\Windows\System32\drivers\etc

  2. 文件内容: 192.168.85.128 www.testnginx.com

 

 

8. The results of the interview are as follows:

Guess you like

Origin blog.csdn.net/zhaofuqiangmycomm/article/details/113996385