openresty / openresty/lua-nginx-module

ngx.exec 会执行到别的项目里面

Open
#2,152 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
11.8k
Forks
2.1k
Avg merge
6h 1m
Merged PRs (30d)
6

Description

nginx version: openresty/1.19.9.1

ubuntu 20.04 apt安装的

upstream gateway-extra.xx.cn{
server 127.0.0.1;
}

upstream xx.com{
server 172.17.0.11;
}

server {
listen 80;
server_name xx.com;

location / {
    access_by_lua_file /data/gateway/index.lua;

    proxy_pass http://$host;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location /gateway/extra/ {
    proxy_pass http://gateway-extra.xx.cn/;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

}

server
{
listen 80;
server_name gateway-extra.xx.cn;
index index.html index.php;
root /data/gateway/extra/public;

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}

location ~ [^/]\.php(/|$)
{
    try_files $uri $uri/ /index.php$is_args$args;

    fastcgi_pass  unix:/run/php/php7.4-fpm.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
    fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/../../:/tmp/:/proc/";
}

}

/data/gateway/index.lua 里面

if uri == "/asd" then
return ngx.exec("/gateway/extra/verify")
end

这里的 ngx.exec("/gateway/extra/verify") 按理说应该放到到php项目里面去
但是大部分时候 会执行到服务器里面的默认项目(服务器里面有很多项目)
就是访问 xx.com/asd 显示的是默认项目的页面 但是有时候又正常 80%的情况到默认项目

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with /data/gateway/index.lua and the two nginx server/location configurations, then reproduce requests to xx.com/asd while observing which server handles the internal redirect. Read the ngx.exec entry point and relevant nginx routing behavior before comparing the configured /gateway/extra/ path with the PHP project's server block. Done means the request consistently reaches the intended PHP project rather than the default site.

Written by the indexing model from the issue text.

Assessment

Tech stack
nginx, php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.