3.反向代理

自己配置 nginx 时, 需保证静态资源路径正确或者能正常转发到反向代理

1.配置站点,点击项目站点名称

2.配置反向代理,代理名称随意填写,添加目标 URL:http://127.0.0.1:8324

注意 这里不能开启缓存功能

3.配置 ws反向代理,点击 配置文件

宝塔版本大于等于7.8版本复制一下内容,替换配置文件

#PROXY-START/

location ^~ /
{
    proxy_pass http://127.0.0.1:8324;
    proxy_http_version 1.1;
    proxy_read_timeout 360s;   
    proxy_redirect off; 
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    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 REMOTE-HOST $remote_addr;

    add_header X-Cache $upstream_cache_status;

    #Set Nginx Cache


    set $static_fileLzXnun8E 0;
    if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
    {
     set $static_fileLzXnun8E 1;
     expires 12h;
        }
    if ( $static_fileLzXnun8E = 0 )
    {
    add_header Cache-Control no-cache;
    }
}

#PROXY-END/

宝塔版本小于7.8 复制以下内容,替换配置文件里10-24行并保存

location /
{
    proxy_pass http://127.0.0.1:8324;
    proxy_http_version 1.1;
    proxy_read_timeout 360s;   
    proxy_redirect off; 
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    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 REMOTE-HOST $remote_addr;

    add_header X-Cache $upstream_cache_status;

    #Set Nginx Cache

        add_header Cache-Control no-cache;
    expires 12h;
}

查看宝塔版本

替换后,点击保存

OK.进行下一步,运行服务