宝塔面板 设置反向代理访问使jsp与php共用一个环境共用一个80端口

日志 专栏收录该内容
246 篇文章 0 订阅

1.反向代理与正向代理

参考:https://blog.csdn.net/zt15732625878/article/details/78941268

2.宝塔面板设置反向代理

我把80端口用作php,8080端口用作jsp。比如访问ys.wjsou.com跳到java.wjsou.com:8080,设置如下

这样就OK了。

自动生成的配置可以参考下:

server
{
    listen 80;
    server_name ys.wjsou.com;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/ys.wjsou.com;
    
    #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
    #error_page 404/404.html;
    #SSL-END
    
    #ERROR-PAGE-START  错误页配置,可以注释、删除或修改
    error_page 404 /404.html;
    error_page 502 /502.html;
    #ERROR-PAGE-END
    
    #PHP-INFO-START  PHP引用配置,可以注释或修改
    #PROXY-START
    location ~ /purge(/.*) { 
        proxy_cache_purge cache_one java.wjsou.com:8080$request_uri$is_args$args;
        #access_log  /www/wwwlogs/ys.wjsou.com_purge_cache.log;
    }
    location / 
    {
        proxy_pass http://java.wjsou.com:8080;
        proxy_set_header Host java.wjsou.com:8080;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
                
        #持久化连接相关配置
        #proxy_connect_timeout 30s;
        #proxy_read_timeout 86400s;
        #proxy_send_timeout 30s;
        #proxy_http_version 1.1;
        #proxy_set_header Upgrade $http_upgrade;
        #proxy_set_header Connection "upgrade";
        
        add_header X-Cache $upstream_cache_status;
        
        expires 12h;
    }
    
    location ~ .*\.(php|jsp|cgi|asp|aspx|flv|swf|xml)?$
    {
        proxy_set_header Host java.wjsou.com:8080;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_pass http://java.wjsou.com:8080;
        
    }
    
    location ~ .*\.(html|htm|png|gif|jpeg|jpg|bmp|js|css)?$
    {
        proxy_set_header Host java.wjsou.com:8080;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_pass http://java.wjsou.com:8080;
        
        #缓存相关配置
        proxy_cache cache_one;
        proxy_cache_key $host$request_uri$is_args$args;
        proxy_cache_valid 200 304 301 302 1h;
        
        expires 24h;
    }
    #PROXY-END

	include enable-php-53.conf;
    #PHP-INFO-END
    
    #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
    include /www/server/panel/vhost/rewrite/ys.wjsou.com.conf;
    #REWRITE-END
    
    #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }
    
    #一键申请SSL证书验证目录相关设置
    location ~ \.well-known{
        allow all;
    }
    
    access_log  /www/wwwlogs/ys.wjsou.com.log;
    error_log  /www/wwwlogs/ys.wjsou.com.error.log;
}

 

 

测试示例:我想通过访问ys.wjsou.com得到www.wjsou.com的内容。设置如下:

自动配置内容:

server
{
    listen 80;
    server_name ys.wjsou.com;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/ys.wjsou.com;
    
    #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
    #error_page 404/404.html;
    #SSL-END
    
    #ERROR-PAGE-START  错误页配置,可以注释、删除或修改
    error_page 404 /404.html;
    error_page 502 /502.html;
    #ERROR-PAGE-END
    
    #PHP-INFO-START  PHP引用配置,可以注释或修改

	#PROXY-START
    location ~ /purge(/.*) { 
        proxy_cache_purge cache_one www.wjsou.com$request_uri$is_args$args;
        #access_log  /www/wwwlogs/ys.wjsou.com_purge_cache.log;
    }
    location / 
    {
        proxy_pass http://www.wjsou.com;
        proxy_set_header Host www.wjsou.com;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
                
        #持久化连接相关配置
        #proxy_connect_timeout 30s;
        #proxy_read_timeout 86400s;
        #proxy_send_timeout 30s;
        #proxy_http_version 1.1;
        #proxy_set_header Upgrade $http_upgrade;
        #proxy_set_header Connection "upgrade";
        
        add_header X-Cache $upstream_cache_status;
        
        expires 12h;
    }
    
    location ~ .*\.(php|jsp|cgi|asp|aspx|flv|swf|xml)?$
    {
        proxy_set_header Host www.wjsou.com;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_pass http://www.wjsou.com;
        
    }
    
    location ~ .*\.(html|htm|png|gif|jpeg|jpg|bmp|js|css)?$
    {
        proxy_set_header Host www.wjsou.com;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_pass http://www.wjsou.com;
        
        #缓存相关配置
        proxy_cache cache_one;
        proxy_cache_key $host$request_uri$is_args$args;
        proxy_cache_valid 200 304 301 302 1h;
        
        expires 24h;
    }
    #PROXY-END

	include enable-php-53.conf;
    #PHP-INFO-END
    
    #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
    include /www/server/panel/vhost/rewrite/ys.wjsou.com.conf;
    #REWRITE-END
    
    #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }
    
    #一键申请SSL证书验证目录相关设置
    location ~ \.well-known{
        allow all;
    }
    
    access_log  /www/wwwlogs/ys.wjsou.com.log;
    error_log  /www/wwwlogs/ys.wjsou.com.error.log;
}

 

  • 0
    点赞
  • 0
    评论
  • 4
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 精致技术 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值