AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / coding / 问题

问题[nginx](coding)

Martin Hope
GrnEyedDvl
Asked: 2025-04-28 16:11:54 +0800 CST

nginx 将 vBulletin 重写为 XenForo

  • 5

这里有一个类似的问题,但答案不起作用,XenForo 的官方答案也不起作用。显然,他们在论坛从 /forums 设置迁移到根域级别时遇到了问题,但修复方法不起作用。

旧链接 https://www.twcenter.net/forums/member.php?10263-Gaius-Baltar

新链接 https://twcenter.net/members/gaius-baltar.10263/

旧链接 https://www.twcenter.net/forums/showthread.php?581961-Name-Change-Requests

新链接 https://twcenter.net/threads/name-change-requests.581961/

这确实对非友好 URL 有效,但我没有很多这样的 URL。

           return 301 /threads/$arg_t/;
        }

        location = /member.php {
           return 301 /members/$arg_u/;
        }

我认为让我困惑的是文本和 ID 之间的切换。在 vBulletin 中,它先 id,再文本

在 XenForo 中它的 the-text.id

nginx
  • 1 个回答
  • 38 Views
Martin Hope
Asem Khen
Asked: 2025-03-04 01:39:30 +0800 CST

NginX 无需通过代理身份验证即可重定向到变量值

  • 5

我在 NginX 代理管理器后面运行 Emby 服务器。尽管 Emby 不支持 SSO,但我仍然能够使用 URL 登录 Web UI:。schenme://emby.domain.com/web/index.html?userId=abc&accessToken=xxx&e=1可以在 Authentik 中生成用于验证 Emby 的此 URI,并且可以在验证后传递该值。我需要在 NginX 中执行此操作的帮助。

我将写下我使用的步骤和方法,以防万一。

在 Authentik > 管理界面 > 目录 > 用户中:编辑所需用户以添加 emby 身份验证。只需在属性部分添加以下值:

emby_password: ****
emby_username: abc

在 Authentik > 管理界面 > 自定义 > 属性映射中创建一个新的范围映射。名称为“Emby Token”,范围名称为“ak_proxy”。表达式需要一个可以从 Emby UI 获取的 API Token。不要忘记编辑 URL,以便 Authentik 可以访问 Emby:

import json
from urllib.parse import urlencode
from urllib.request import Request, urlopen

if request.user.username == "":
  return "null"
else:
  embyuser = request.user.attributes.get("emby_username", "")
  embypass = request.user.attributes.get("emby_password", "")

base_url = "http://embyserver:80"
end_point = "/Users/AuthenticateByName?api_key=xyz"
json_data = {'Username': embyuser,'Pw': embypass}
postdata = json.dumps(json_data).encode()
headers = {"Content-Type": "application/json; charset=UTF-8"}

try:
  httprequest = Request(base_url + end_point, data=postdata, method="POST", headers=headers)
  with urlopen(httprequest) as response:
    responddata = json.loads(response.read().decode())
  AccessToken = responddata['AccessToken']
  UserId = responddata['User']['Id']
except:
  AccessToken = "null"
  UserId = "null"
return {"ak_proxy": {"user_attributes": {"additionalHeaders": {"X-Emby-Uri": "/web/index.html?userId=" + UserId + "&accessToken=" + AccessToken + "&e=1"}}}}

如果 Authentik 可以访问 Emby Server 并且正确提供了登录属性,则此范围应该返回/web/index.html?userId=abc&accessToken=xxx&e=1可用于登录的内容。

之后,我创建了一个应用程序和提供程序,并将它们添加到 Outpost。身份验证按预期工作。尝试在 NginX 代理管理器中传递此值,如下所示,遗憾的是不起作用:

client_max_body_size 100M;
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 X-Forwarded-Proto $scheme;
proxy_set_header Sec-WebSocket-Extensions $http_sec_websocket_extensions;
proxy_set_header Sec-WebSocket-Key $http_sec_websocket_key;
proxy_set_header Sec-WebSocket-Version $http_sec_websocket_version;
#proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_redirect off;
proxy_buffering off;
location / {
    proxy_pass $forward_scheme://$server:$port;
}
location /ssoauth {
    proxy_set_header Upgrade $http_upgrade;
    auth_request     /outpost.goauthentik.io/auth/nginx;
    error_page       401 = gnin;
    auth_request_set $auth_cookie $upstream_http_set_cookie;
    add_header       Set-Cookie $auth_cookie;
    auth_request_set $authentik_embyuri $upstream_http_x_emby_uri;
    rewrite ^ $authentik_embyuri;
    proxy_pass  $forward_scheme://$server:$port/;
}
location /outpost.goauthentik.io {
    proxy_pass              https://authentik-server:9443/outpost.goauthentik.io;
    proxy_set_header        Host $host;
    proxy_set_header        X-Original-URL $scheme://$http_host$request_uri;
    add_header              Set-Cookie $auth_cookie;
    auth_request_set        $auth_cookie $upstream_http_set_cookie;
    proxy_pass_request_body off;
    proxy_set_header        Content-Length "";
}
location gnin {
    internal;
    add_header Set-Cookie $auth_cookie;
    return 302 /outpost.goauthentik.io/start?rd=$request_uri;
}

通过转到schenme://emby.domain.com/ssoauth,我被提升为使用 Authentik 登录。身份验证后,使用 加载登录 uri auth_request_set $authentik_embyuri $upstream_http_x_emby_uri;。检查值并测试它,我能够登录。但是,将 uri 从/SSO auto重写为$authentik_embyuri使用rewrite ^ $authentik_embyuri;不起作用。使用return绕过 Authentik 登录过程,并且不会加载登录 uri。

我希望最终目标和方法是明确的。

问题仍然存在:我如何管理从NginX重定向/SSO auto到的返回值?我可以通过覆盖标头来做到这一点吗(尝试过这个没有用)?$authentik_embyuriLocation

nginx
  • 1 个回答
  • 39 Views
Martin Hope
William Turrell
Asked: 2025-02-11 23:58:21 +0800 CST

在 Nginx 中使用查询字符串阻止 URL

  • 5

我正在尝试使用 Nginx Location 来阻止类似这样的请求,这些请求会导致 WordPress(和多语言 WPML 插件)出现加载问题:

GET /foo/bar/?s=/?s=/?s=/?s=/?s=/?s=/?s=/?s=/?s=/?s=/ HTTP/1.1

但是将其简化为以下内容并不匹配:

location ~* \?s= {
  return 404;
}

即使我已经:

  • 将其置于所有其他位置指令之上
  • 逃脱了?,但没有逃脱=(也尝试过)
  • 删除^并$避免斜线造成任何混淆
  • 用于~*不区分大小写

(我可以确认它将location foobar正确匹配 URL 中任何位置的“foobar”。)

nginx
  • 2 个回答
  • 38 Views
Martin Hope
Seaky Lone
Asked: 2025-02-09 00:15:10 +0800 CST

nginx proxy_pass 无法与 s3 配合使用并将所有请求重定向到 try_file

  • 5

我有一个 Nginx 配置,其中我将请求代理到外部资源(s3 服务),但是当尝试访问特定静态文件时,Nginx 会回退到 try_files 指令,而不是代理请求。以下是简化的配置:

    server {
        listen       443 ssl;
        server_name  test.lightningmoment.com;

        location /static/ {
            proxy_pass https://haiskynology-test-web.oss-cn-hangzhou.aliyuncs.com/com.haiskynology.lightningmoment.web/test/build/static/;
            proxy_set_header Host test-cdn.lightningmoment.com;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }

        location / {
            proxy_pass https://haiskynology-test-web.oss-cn-hangzhou.aliyuncs.com/com.haiskynology.lightningmoment.web/test/build/;
            proxy_set_header Host test-cdn.lightningmoment.com;

            try_files $uri $uri/ /index.html;
        }

    }

该文件logo64.png存在于以下 OSS 路径中:

https://haiskynology-test-web.oss-cn-hangzhou.aliyuncs.com/com.haiskynology.lightningmoment.web/test/build/logo64.png。

当我尝试访问https://test.lightningmoment.com/logo64.png时,会导致 Nginx 回退到 try_files 逻辑并提供 index.html 文件,而不是将请求代理到 OSS 服务器。

我确认该文件存在,并且可以使用如下手动代理配置直接访问:

location /logo64.png {
    proxy_pass https://haiskynology-test-web.oss-cn-hangzhou.aliyuncs.com/com.haiskynology.lightningmoment.web/test/build/logo64.png;
    proxy_set_header Host test-cdn.lightningmoment.com;
}

同样,除非我明确添加配置,否则我无法访问静态文件夹下的文件location /static/。

我的问题:为什么对 /logo64.png 的请求会回退到 try_files?

我该如何修复 proxy_pass 以正确转发请求而不陷入 try_files 后备逻辑?

我可以采取哪些调试步骤来进一步诊断这个问题?

我预期用户以nginx作为第一层入口来访问React网站test.lightningmoment.com,然后我想给它添加一个cdn。

提前致谢!

nginx
  • 1 个回答
  • 38 Views
Martin Hope
Dan
Asked: 2025-01-20 11:56:24 +0800 CST

如何在 Openresty 中使用 Lua 变量加载模块?

  • 5

尝试根据变量中的值加载模块。这可能吗?

local moduletoload = "login"    
local mod_action = require moduletoload

谢谢

nginx
  • 1 个回答
  • 24 Views
Martin Hope
umitkilic
Asked: 2025-01-13 21:53:28 +0800 CST

在 Hyperledger Fabric 中使用 nginx 对排序节点进行负载平衡

  • 2

我使用 Hyperledger Fabric 和 Docker 创建了一个网络。此网络中有 3 个订购方和 2 个组织。我将使用 Hyperledger Caliper 测试此网络。网络和 Caliper 运行正常。到目前为止,一切都已准备就绪,但有一件事浮现在我的脑海中。互联网上总是有单个订购方的示例。Hyperledger Fabric 是否有一个内部机制来在 3 个订购方上分配负载?据我所知,没有。那么,如果我想使用 nginx 进行负载平衡,我该如何设置?

nginx
  • 1 个回答
  • 25 Views
Martin Hope
Mr Heelis
Asked: 2024-10-19 22:39:08 +0800 CST

nginx 转发通配符 URL

  • 5

有人可以帮助我设置执行以下操作的 nginx 转发吗:

这是我目前所拥有的。我本来打算改编它,但说实话我无法开始

location ~* ^/pdf/(.*)$ {
      rewrite ^/pdf/(\d+)*$ /pdf.php;
 }

    

我希望:

  • 匹配符合以下格式的任何 URL
    • https://example.com/pdf/My-Old-Man
    • 或者https://example.com/pdf/My-Old-Man/
    • https://example.com/pdf/Big-Hamster
    • 或https://example.com/pdf/Big-Hamster/ 转发至pdf.php
  • 不pdf.php匹配直接呼叫
  • 转发 /My-Old-Man 部分,以便我稍后可以在我的 php 中将其作为 '$_SERVER['QUERY_STRING']' 的一部分读取(以查询数据库)
  • 禁止任何事情https://example.com/pdf/My-Old-Man/bobchips

我知道这要求太高,但我认为这种事情确实很有用,而且我在互联网上没看到有人这样做。

nginx
  • 1 个回答
  • 8 Views
Martin Hope
Khadijah Celestine
Asked: 2024-09-02 07:46:43 +0800 CST

如何在 nginx 中对本地主机上的 3 个端口进行负载平衡?

  • 5

我有 3 个端口正在加载不同的内容,我想从端口 8080 对它们进行负载平衡。我是 nginx 新手,我觉得在 nginx 上提供内容方面,我有一些基本的东西我不太理解。我的 3 个端口独立工作,但没有负载平衡。我该如何编辑配置以在这 3 个端口之间实现负载平衡?

upstream backend {
    server localhost:8081;
    server localhost:8082;
    server localhost:8083;
}

server {
    listen 8080;
    listen [::]:8080;

    server_name _;

    root /var/www/html;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

# Default server configuration
#
server {
    listen 8081 default_server;
    listen [::]:8081 default_server;

    root /var/www/n81;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

}

server {
    listen 8082 default_server;
    listen [::]:8082 default_server;

    root /var/www/n82;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

}

server {
    listen 8083 default_server;
    listen [::]:8083 default_server;

    root /var/www/n83;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

}

nginx
  • 1 个回答
  • 24 Views
Martin Hope
leopoodle
Asked: 2024-05-26 12:35:34 +0800 CST

nginx 服务器可以充当 https 和 http 后端端点的删除代理吗?

  • 5

我有 NGINX 服务器作为反向代理。我想同时监听端口 80 (http) 和 443 (https)。我希望 http 和 https 的请求路径是不同的,因为它们向客户端提供不同的信息。/api/plain_http/xxxx和/api/ssl_http/yyyy

前者 (http) 不会提供任何敏感信息,因此可以使用 http。后者可能包含敏感内容,因此我们希望强制执行 TLS 和 authz/authn。

我确信 NGINX 反向代理可以做到这一点,但我想再次确认配置文件将是什么样子来支持这一点。

nginx
  • 1 个回答
  • 14 Views
Martin Hope
Cursed_Sauce
Asked: 2024-01-15 18:20:32 +0800 CST

Nginx 重写规则错过第二个捕获组

  • 6

我正在尝试通过 Nginx 将我的 MediaWiki 站点地图 URL 重写到 S3 上的正确位置,因为 MediaWiki 生成带有如下 URL 的 sitemap.xml 页面 https://subdomain.domain.net/databasename/sitemaps/sitemap-databasename-NS_0-0.xml.gz:它们在 S3 中的格式相同,只是域是“static.domain.net”而不是实际站点的子域。

我尝试了几种不同的重写规则,但这个规则最接近我所需要的:

        location ~ /([^/]+)/sitemaps/(sitemap-[^\/]+\.xml\.gz)$ {
        rewrite https://static.domain.net/$1/sitemaps/$2 permanent;
        }

但这会将 url 重写为: https://static.domain.net/databasename/sitemaps/,没有第二个捕获组。我已经测试了 regex101 中的正则表达式,它似乎确实匹配这两个组,但由于某种原因,Nginx 在重定向时缺少第二个捕获组 - 是什么原因导致的?我只需要捕获这两个组并将 URL 重定向到 static.domain.net 而不是 subdomain.domain.net。

nginx
  • 1 个回答
  • 45 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve