yxl_long
yxl_long
采纳率0%
2020-07-31 19:46 阅读 205

使用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条回答 默认 最新

相关推荐