• nginx + tomcat 反向代理


    简单的配置:
    # my test java+nginx project

    server {
    listen 8080;
    server_name localhost;
    root /home/user/Desktop/html/testProject/src/web/;
    index index.html index.htm index.php;
    
    access_log /var/log/nginx/localhost-access.log;
    error_log /var/log/nginx/localhost-error.log;
    
    location / {
    try_files $uri $uri/ /index.html?$args;
    #try_files $uri $uri/ =404;
    
    }
    
    location /api/ {#过滤api的请求
    proxy_pass http://localhost:8889/; #反向代理
    #proxy_redirect off; 
    #proxy_redirect http://localhost:8889/ http://$host:$server_port
    #proxy_redirect http://localhost:8889/ http://localhost:8080/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; 
    #client_max_body_size 100m; 
    #client_body_buffer_size 128k; 
    #proxy_connect_timeout 90; 
    #proxy_send_timeout 90; 
    #proxy_read_timeout 90; 
    #proxy_buffer_size 4k; 
    #proxy_buffers 4 32k; 
    #proxy_busy_buffers_size 64k; 
    #proxy_temp_file_write_size 64k; 
    # save only session for a user request 
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    add_header From localhost:8080/api/Test;
    proxy_cookie_path /Test/ /; #设置cookie 路径,已达到请求tomcat的是同一个session.
    proxy_set_header Cookie $http_cookie;
    }
    
    location ~ /.(ht|svn|git) {
    deny all;
    }
    
    }
  • 相关阅读:
    spring-cloud Feign
    spring-cloud eureka注册发现
    spring-cloud zuul网关
    正则表达式整理
    nginx配置-Rewrite
    nginx配置-main
    nginx用途
    Java命令行命令
    Task
    JavaScript难点整理
  • 原文地址:https://www.cnblogs.com/guoke-jsp/p/5082083.html
Copyright © 2020-2023  润新知