nginx 전후 단 분리 실현

글 목록
  • nginx 전후 단 분리 실현
  • 1. nginx 설치
  • 2. conf 설정
  • 2.1. 전단 코드 위치 설정
  • 2.2. 배경 설정 차단 요청
  • 2.3, 전체 설정



  • nginx 전후 단 분리 실현
    1. nginx 설치
    레 퍼 런 스https://blog.csdn.net/mybook201314/article/details/73604640
    2, 설정 conf
      :nginx/conf/nginx.conf
    

    2.1 전단 코드 위치 설정
    location / {
         
    	# root        Linux  :/home/frontend/xxx
    	root   E:\\desktop\\HTML;
    	index  index.html index.htm;
    }
    

    2.2 배경 설정 차단 요청
    #    
    #         /api      
    #         http://localhost:8080/backend_project_name/api/......
    location ~ ^/api {
         
    
    	proxy_set_header Host $host;
    	proxy_set_header X-Real-Ip $remote_addr;
    	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    	proxy_set_header X-Forworded-For $http_x_forwarded_for;
    	
    	## allow     ,    IP         
    	allow 192.168.1.101;
    	allow 192.168.1.102;
    	
    	#   cookie
    	proxy_cookie_path //backend_project_name/ / ;
    	
    	#            
    	#         /,    ,      
    	rewrite /(.+)$ /backend_project_name/$1 break;
    	
    	#       
    	proxy_pass   http://localhost:8080;
    }
    

    2.3. 전체 설정
    #  Nginx         
    #user  nobody;
    
    #nginx   ,       CPU    
    worker_processes  1;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    #    
    #pid        logs/nginx.pid;
    
    
    events {
         
        worker_connections  1024;
    }
    
    
    #http   
    http {
         
        include       mime.types;
        default_type  application/octet-stream;
    
        sendfile        on;
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
        keepalive_timeout  65;
    
        #gzip  on;
    
    	##             ,      
        server {
         
    	
    		// nginx      
            listen       80;
    		
    		// nginx    
            server_name  localhost;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
    		//       
            location / {
         
    			# root        Linux  :/home/frontend/xxx
                root   E:\\desktop\\HTML;
                index  index.html index.htm;
            }
    
            
            #  500 
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
         
                root   html;
            }
    
    		#    
    		#         /api      
    		#         http://localhost:8080/backend_project_name/api/......
            location ~ ^/api {
         
    		
    			proxy_set_header Host $host;
    			proxy_set_header X-Real-Ip $remote_addr;
    			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    			proxy_set_header X-Forworded-For $http_x_forwarded_for;
    			
    			#    cookie
    			proxy_cookie_path //backend_project_name/ / ;
    			
    			#            
    			#         /,    ,      
    			rewrite /(.+)$ /backend_project_name/$1 break;
    
    			#       
                proxy_pass   http://localhost:8080;
            }
        }
    }
    
    

    좋은 웹페이지 즐겨찾기