Articles of 重写

在nginx中重写规则

我正在使用php-fpm将Apache应用程序从Apache移动到Nginx。 我差不多完成了,除了一个我在Nginx中没有做的重写指令。 以下是我需要端口的Apacheconfiguration的摘录: # Handle alianza.quehambre.cl RewriteCond %{HTTP_HOST} ^alianza\.quehambre\.cl [NC] RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-l RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !(api|get)/(.*) RewriteRule ^(.*)$ /index.php/get/$1 [L,QSA] 完整的Nginxconfiguration在这个要点 ,包括我目前的非工作尝试写出上述规则。

Nginx的重写问题

我想为我的虚拟服务器的特定configuration,但我有一个问题,解释,以Nginx的:) 它很简单。 如果URI看起来像 example.com/whatever_1/whatever_2/…/whatever_n 我想重写它 example.com/index.php?request=whatever_1/whatever_2/…/whatever_n 第二个是如果URI以/administration/ like开头 example.com/administration/whatever_1/…/whatever_n 我想把它改写成 example.com/administration/index.php?request=whatever_1/…/whatever_n 我正在修理周围,并试图: server { # listen 80; server_name example.com; index index.html index.php; root /srv/example/; location ~ /administration/(.*)$ { if (!-e $request_filename) { rewrite ^/(.*)$ /administration/index.php?request=$1 last; } break; #tried with and without it } location / #tried with and without this location block { if […]

Nginx在redirect到不同的域时不发送auth头文件

我有以下设置: server { server_name some.server; location / { rewrite ^ https://otherserver.com permanent; } } redirect按预期工作,但发送到第一个请求的Authorization标头不会发送到其他服务器。 我怎样才能解决这个问题?

nginx重写规则,正则expression式只应用于一个子目录

我已经沮丧了几天想弄明白这一点,所以任何意见/帮助将不胜感激! 我最近在somehost.com上添加了一个名为/links到某个站点的部分,但似乎无法得到这个目录的重写规则(见下文)。 域的所有其他path工作正常(例如说一些hosthost /浏览器/video/无论redirect到somehost.com/by/whatever/罚款)和所有其他重写规则似乎仍然工作很好,这只是新添加location /links/部分我的conf在东西分崩离析。 下面的conf在第27行失败 – 使用service nginx restart时得到的错误是: 指令“rewrite”没有以“;”结尾。 但是我可以看到终点线终止于一个; 所以我不确定有什么问题。 也许正则expression式的东西? 我的nginx conf在下面。 任何想要改变什么来获取像somehost.com/links/page/3或somehost.com/links/tag/sometopic/page/2工作的url? 谢谢! server { server_name somehost.com; listen 80; root /var/www/somehost.com; include /etc/nginx/php.conf; location / { index index.php; access_log /var/log/nginx/somehost.com.log; #handle old variable redirects first, before dealing with current permalinks rewrite ^/?browse/video/(.*) /by/$1 permanent; #set a 30-day expires header on […]

Apache2:尝试将子域映射到子目录

所以基本上我想有:sub.domain.com/ 什么 – > domain.com/asub / 什么 我对此有点新,有点困惑。 我做的第一件事就是configuration我的DNS设置,以便sub.domain.com使用CNAME访问domain.com(Alogging和IP会更好吗?) 接下来,我进入我的VirtualHost文件,并有: RewriteEngine on RewriteCond %{HTTP_HOST} www.(.+) [NC] RewriteRule ^/(.*) http://domain.com/$1 [R] RewriteCond %{HTTP_HOST} ^sub.domain.com RewriteRule ^/(.*) http://domain.com/asub/$1 [R] 所以第一个规则是为了处理www。 并确保被正确捕获,它的工作原理。 第二个规则是我为子域映射添加的东西,它似乎没有做任何事情

NginX导致PHP文件被执行两次

我处于一个困难的地方,试图弄明白为什么会这样。 出于某种原因,当我打开我的网站的index.php文件正在执行。 我已经能够通过添加file_put_contents('runs.txt', 'executed'.PHP_EOL, FILE_APPEND);将其缩小到NginX / PHP-FPM file_put_contents('runs.txt', 'executed'.PHP_EOL, FILE_APPEND); 到index.php的顶部,并使用网站和命令行执行它。 如果我从命令行执行它,它只输出一个executed ,而如果我从网站(通过NginX) executed它输出两个executed 。 该脚本也没有redirect到自身,因为它只是返回200响应代码。 除了通过执行脚本两次使用更多的内存之外,还通过使CSRF再次生成来消除CSRF保护,因此CSRF是无用的。 下面是我的nginxconfiguration文件: nginx.conf user nginx; worker_processes 2; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr – $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log […]

Nginx从请求URI中提取顶级目录名称

我需要能够使用$request_uri顶级目录,例如: /dir/sub/slug – > /dir 我读了这个问题的答案: 如何从请求中提取只有文件名uri # Gets the basename of the original request map $request_uri $request_basename { ~/(?<captured_request_basename>[^/?]*)(?:\?|$) $captured_request_basename; } # Gets the basename of the current uri map $uri $basename { ~/(?<captured_basename>[^/]*)$ $captured_basename; } 它似乎与我所需要的接近,这是如何工作的? 是否有可能被修改,以获得顶部目录呢? 谢谢!

Apache2和rewritemap – 几个小时的尝试

我坚持与rewritemap问题。 我想要做的是将成千上万的几乎随机的url重新导向新的url。 我将手动build立地图,但我需要这个代码来工作。 RewriteCond %{HTTP_HOST}%{REQUEST_URI}\?%{QUERY_STRING} (^example\.com.abcd.cat_4)(.*) RewriteRule .* ${url_rewrite_map:$1|NOTFOUND}? [R=301,L] 我想地图看起来像这样: example.com/abcd/cat_4 http://example.com/345_exact_address_of_page 旧的url看起来像: http://example.com/abcd/cat_4=0?Xi4B7WoN;;54 我想让他们改写成: http://example.com/345_exact_address_of_page 我尝试了很多东西,但我无法做到这一点…你能帮我吗?

Apache:环境variables的范围

虽然有关于Apache环境variables的文档,但我无法find一个重要问题的答案。 想象一下,我使用重写规则来设置环境variables RewriteRule … … [E=something:1] 什么是“东西”的范围 – 全球的Apache服务器(这意味着“东西”将可用于其他请求交易),这个请求(意味着“东西”只适用于这个HTTP请求(及其相关的处理 – 但什么关于内部redirect和其他内部的东西 – 他们认为是这个请求,或另一个?),并可能在另一个(并发)请求中设置不同?

更大的文件的IIS ARR /反向代理502错误

我有一个用Python编写的API,通过ISAPI扩展PyISAPIe访问IIS 7.5。 我认为从我们的主站点分离这个API是明智的,所以它在不同的站点通过8008端口访问。 为了能够使用像http://domain/api这样的URL访问API,我已经在IIS中使用ARR和URL Rewrite创build了一个反向代理规则,以便http://domain/api被redirect到http://domain:8008 。 反向代理似乎工作正常,我在大多数情况下从API接收正确的响应(API返回JSON)。 但是,在某些情况下,我收到502错误,并显示以下消息: 502 – Web server received an invalid response while acting as a gateway or proxy server. 这似乎只发生在JSON响应超过一定的大小(在我的testing中大约125KB) – 对于较小的尺寸,一切似乎正常工作。 我已经尝试在代理设置中增加Response buffer threshold ,不起作用。 添加信息 在日志中,我可以看到8008端口上的站点请求成功并返回200状态码。 激活失败的请求追踪之后,唯一的错误/警告如下(这是在收到来自其他站点的响应之后 – 请参阅前一点): MODULE_SET_RESPONSE_ERROR_STATUS Warning ModuleName="ApplicationRequestRouting", Notification="EXECUTE_REQUEST_HANDLER", HttpStatus="502", HttpReason="Bad Gateway", HttpSubStatus="3", ErrorCode="2147954552"ConfigExceptionInfo=""