yxl_long 2020-07-31 19:46 采纳率: 0%
浏览 713

使用openresty渲染页面,然后用nginx代理访问,为什么一直报错说是404

代理过后访问404:
图片说明

虚拟机ip:192.168.206.99
虚拟机内项目配置:

upstream backend {  
    server 192.168.206.1:8084 max_fails=5 fail_timeout=10s weight=1;    
    keepalive 100;  
}  

server {  
    listen       80; 
    set $template_root "/usr/resty/templates"; 
    # 我们要求内部请求以 /backend开头,与其他请求区分
    location ~ /backend/(.*) {  
        #internal;  
        keepalive_timeout   30s;  
        keepalive_requests  1000;  
        #支持keep-alive  
        proxy_http_version 1.1;  
        proxy_set_header Connection "";  

        rewrite /backend(/.*) $1 break;  
        proxy_pass_request_headers off;  
        #more_clear_input_headers Accept-Encoding;  
        proxy_next_upstream error timeout;  
        proxy_pass http://backend/;
    }

location ~ /item/(\d+).html$ {
    # 获取路径参数
    set $spuId $1;
    # 禁止除了www.leyou.com以外的请求访问
    if ($host !~ "^www\.leyou\.com$") {  
        return 403;  
    }
    # 关闭缓存/打开缓存
    lua_code_cache on; 
    default_type 'text/html';  
    charset utf-8;
    # 指定请求交给lua/item.lua脚本来处理
    content_by_lua_file lua/item.lua;
}

}

nginx配置:

worker_processes  1;
error_log logs/error.log;
events {
    worker_connections 1024;
}  
http {
    lua_package_path "/usr/local/openresty/lualib/?.lua;;";  #lua 模块  
    lua_package_cpath "/usr/local/openresty/lualib/?.so;;";  #c模块 
    lua_shared_dict item_local_cache 50m; #共享全局变量,在所有worker间共享

    default_type  text/html; # 默认响应类型是html
    # include lua.conf;    # 引入一个lua.conf文件
    include leyou.conf;
}

本地hosts文件配置:

server {
    listen       80;
    server_name  www.leyou.com;

    location /item {
        # 携带hosts地址,避免因代理导致host丢失
        proxy_set_header Host       $host;
        proxy_pass   http://192.168.206.99;
    }

    location / {
        root     E:/everyday/review/leyou-portal;
    }
}
  • 写回答

1条回答 默认 最新

  • dabocaiqq 2020-08-01 12:45
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊