标签: rewrite

Nginx 代理/上游重定向使用错误的端口和协议

我使用 NGINX 服务器作为其他一些 NGINX 服务器的 ssl 代理。不幸的是,如果请求被上游服务器重定向,则位置字段包含错误的目标端口。

curl -v "https://example.com/site":

> GET /site HTTP/2
> Host: example.com
> User-Agent: curl/7.58.0
> Accept: */*
> 
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 301 
< server: nginx
< date: Sun, 18 Mar 2018 20:01:44 GMT
< content-type: text/html
< content-length: 178
< location: http://example.com:9101/site/
< strict-transport-security: max-age=15768000; includeSubDomains
Run Code Online (Sandbox Code Playgroud)

NGINX 代理:

# Proxy: example.com
####################

server {
  listen 0.0.0.0:80;
  listen [::]:80;
  server_name example.com;
  root /srv/www/_empty;
  location / { return 301 https://example.com$request_uri; …
Run Code Online (Sandbox Code Playgroud)

rewrite nginx proxy https

5
推荐指数
1
解决办法
7722
查看次数

如何添加/忽略 htaccess 文件中的子文件夹?

我已经在以下位置构建了一个应用程序http://url/sdf19/

我在 /sdf19/ 中放置了一个 .htaccess ,其中包含用于干净网址的 RewriteRule 。

但我已经构建了一个PDF生成工具,它位于子文件夹中/inc/tools。我需要直接链接到它才能在标题之前运行。

尽管进行了几个小时的搜索、尝试片段、生成器等,但http://url/sdf19/inc/tools如果现有的 RewriteRule 集不接管,我无法获得任何请求被允许

这是我的起始文件

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([a-z]+)\/?$ index.php?page=$1 [NC]
RewriteRule ^([a-z]+)\/([0-9]+)\/?$ index.php?page=$1&id=$2 [NC]
RewriteRule ^([a-z]+)\/([a-z]+)\/?$ index.php?page=$1&action=$2 [NC]
RewriteRule ^([a-z]+)\/([a-z]+)\/([0-9]+)\/?$ index.php?page=$1&action=$2&id=$3 [NC]
Run Code Online (Sandbox Code Playgroud)

尝试过的事情:

我尝试将其添加到第 4 行; RewriteCond %{REQUEST_URI} !^ inc/tools/ [NC] 这给出了 RewriteCond: bad argument line 错误

我尝试将其添加到第 2 行;

RewriteCond %{REQUEST_URI} ^/inc/tools/(.*)$
RewriteRule ^.*$ - [L]
Run Code Online (Sandbox Code Playgroud)

我尝试在/inc/toolsRewriteEngine 关闭的情况下添加 .htaccess,但没有成功。

我尝试了顶帖上链接的 .htaccess 测试器,但是虽然我的文件(上面)可以在 IRL 中工作,但它会为那里的所有内容生成“未满足规则”!

长话短说

期望的结果是我可以允许直接访问http://url/sdf19/inc/tools>到目前为止我尝试过的所有内容,我被重定向到基地http://url/sdf19/

mod-rewrite rewrite .htaccess

5
推荐指数
1
解决办法
4995
查看次数

在nginx上重写一个子目录到root

假设我有一个站点http://domain/,我将一些文件放在一个子目录中/html_root/app/,我使用以下重写规则将此文件夹重写到我的根目录:

location / {
    root /html_root;
    index index.php index.html index.htm;

    # Map http://domain/x to /app/x unless there is a x in the web root.
    if (!-f $request_filename){
        set $to_root 1$to_root;
    }
    if (!-d $request_filename){
        set $to_root 2$to_root;
    }
    if ($uri !~ "app/"){
        set $to_root 3$to_root;
    }
    if ($to_root = "321"){
        rewrite ^/(.+)$ /app/$1;
    }

    # Map http://domain/ to /app/.
    rewrite ^/$ /app/ last;
}
Run Code Online (Sandbox Code Playgroud)

我知道这不是一个聪明的方法,因为我有另一个子目录/html_root/blog/并且我希望它可以通过http://domain/blog/.

我的问题是,上面的重写规则可以正常工作,但仍然存在一些问题:如果我访问

http://domain/a-simple-page/(改写自http://domain/app/a-simple-page/

它工作正常,但如果我访问

http://domain/a-simple-page …

rewrite nginx

4
推荐指数
1
解决办法
9258
查看次数

这是我在 IIS 7.5 上的 Web.Config

我用谷歌搜索了这个,发现它存储在我的 asp 框架文件夹中......但我可以知道哪个是适合我的特定应用程序的 web.config 文件吗?有太多的应用程序正在运行...我发现很多 web.config

我正在使用窗口服务器 64(所以有框架和框架 64)

我的应用程序池是(应用程序名称)v4;管道集成

rewrite iis-7.5 windows-server-2008-r2

4
推荐指数
1
解决办法
8670
查看次数

在地址栏中隐藏非标准端口?

某些应用程序(例如 Plone)默认在 80 以外的端口(例如 8080)上提供 http 服务。

通常,要查看这些 web 应用程序,您需要加载http://mysite.tld:8080而不仅仅是http://mysite.tld(假设您还有一个在端口 80 上运行的“标准”网站)。

有没有办法伪装和/或隐藏地址栏中显示的端口号,以便访问者不知道他们不在标准的 http 端口上?如果是这样,如何?URL 重写是正确的方法吗?

rewrite http port

4
推荐指数
2
解决办法
2576
查看次数

nginx proxypass 重写基本 URL

我正在尝试设置 Nginx 以使用 proxy_pass 将请求转发到多个后端服务。

其中一些不支持在子文件夹下访问,因此我必须添加重写以剥离附加的子文件夹,以允许从同一端口访问它们。

关于改进重写的任何提示?

卷曲输出;

:~$ curl -I -k https://example.net/internal
HTTP/1.1 404 Not Found
Server: nginx/1.0.5
Date: Thu, 19 Jan 2012 22:30:46 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Content-Length: 145

:~$ curl -I -k https://example.net/internal/
HTTP/1.1 200 OK
Server: nginx/1.0.5
Date: Thu, 19 Jan 2012 22:31:12 GMT
Content-Type: text/html
Connection: keep-alive
Content-Length: 1285
Accept-Ranges: bytes
Last-Modified: Wed, 18 Jan 2012 01:35:21 GMT
Run Code Online (Sandbox Code Playgroud)

配置文件;

代理配置文件

location /internal {
    rewrite           ^/internal/(.*) /$1 break;
    proxy_pass        http://localhost:8081/internal;
    include proxy.inc;
}
.... …
Run Code Online (Sandbox Code Playgroud)

rewrite nginx reverse-proxy

4
推荐指数
1
解决办法
3万
查看次数

当我的应用程序关闭时由 nginx 提供的静态错误页面

如果我的(Rails)应用程序关闭或正在进行数据库维护或其他任何事情,我想在 nginx 级别指定以提供静态页面。所以像http://example.com/*这样的每个 URL都应该提供一个静态的 html 文件,比如 /var/www/example/foo.html。

试图在我的 nginx 配置中指定它给了我适合和无限循环等等。

我正在尝试类似的事情

location / {
  root /var/www/example;
  index foo.html;
  rewrite ^/.+$ foo.html;
}
Run Code Online (Sandbox Code Playgroud)

您如何让域中的每个 URL 为单个静态文件提供服务?

rewrite nginx

4
推荐指数
1
解决办法
3069
查看次数

Nginx 重写除 index 之外的所有 html 文件

我在 Nginx 重写方面遇到了一些麻烦。我最近被博客转移到了一个新引擎,URL 结构发生了变化。在我的旧博客引擎上,帖子位于带有表单的 URL 上,http://$host/yyyy/mm/title.html但是在新引擎上,它们具有表单http://$host/yyyy/mm/title/。服务器返回的实际文件位于/yyyy/mm/title/index.html.

为了确保旧帖子中的链接仍然有效,我想在 Nginx 中进行重写,如下所示:

rewrite ^/(\d\d\d\d)/(\d\d)/(.+)\.html$ $scheme://$host/$1/$2/$3/ permanent;
Run Code Online (Sandbox Code Playgroud)

不幸的是,这种捕捞任何有目的.html包括index.html,所以逛格式的URL/(\d\d\d\d/)/(\d\d)/(.+)/导致重定向循环(nginx的内部尝试使用/$1/$2/$3/index.html的方法,其重定向/$1/$2/$3/,其重定向回index.html的,等等)。

如果可能的话,我宁愿不使用 if 语句。有任何想法吗?

作为参考,该站点是静态的,我的服务器配置看起来像这样(这里没什么特别的):

server {
  listen      [::]:80;
  server_name blog.samwhited.com;
  root /var/www/blog.samwhited.com;
  charset utf-8;
  location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires max;
    log_not_found off;
  }
  error_page 404 /error/404.html;
  error_page 403 /error/403.html;
  location /error/ { internal; }
}
Run Code Online (Sandbox Code Playgroud)

以下是预期重定向行为的快速示例:

http://blog.samwhited.com/2008/09/test.html -> http://blog.samwhited.com/2008/08/test/

如果 index.html 可以隐藏也很好。我在网上找到的任何东西都没有奏效。所以这也可以:

http://blog.samwhited.com/2008/09/test/index.html -> http://blog.samwhited.com/2008/09/test/

rewrite nginx

4
推荐指数
1
解决办法
3768
查看次数

Nginx 重写:从带有参数的 URL 中删除 .html

如何从带有参数的 url 中删除 .html?

例如:http : //www.domain.com/somepage.html?argument= whole& bunch=a-lot

到:

http://www.domain.com/somepage?argument=whole&bunch=a-lot

我试过了

    location / {
    index index.html index.php; 
            rewrite ^\.html(.*)$ $1 last;
            try_files $uri $uri/ @handler; 
            expires 30d; ## Assume all files are cachable
     }
Run Code Online (Sandbox Code Playgroud)

和一堆其他建议,但似乎无法让它发挥作用....

Tnx

rewrite nginx

4
推荐指数
1
解决办法
5965
查看次数

使用字符串替换的 nginx url 重写

我需要知道我的 url 是否包含一个小的 substr,保持 url 原样并只重写那一小部分,我该如何完成?

例如:

http://foobar.com/foo-bar-substrtocatch-baz 
Run Code Online (Sandbox Code Playgroud)

应该成为

http://foobar.com/foo-bar-changedsubstr-baz
Run Code Online (Sandbox Code Playgroud)

提前致谢...

rewrite nginx

4
推荐指数
1
解决办法
2万
查看次数