我的 Nginx 站点配置文件中有以下内容:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.php index.html index.htm;
server_name example.com;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
server {
listen 80;
server_name example2.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass …Run Code Online (Sandbox Code Playgroud) 我有以下 Nginx 服务器块:
server {
listen 80;
listen [::]:80;
server_name example.com;
root /usr/share/nginx/html;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://localhost/page-1/;
}
}
Run Code Online (Sandbox Code Playgroud)
我希望当用户在 example.com 上收到 404 错误时,proxy_pass应该更改为直接访问http://localhost/example-404/.
然而,这个服务器块和两者的服务器块http://localhost具有相同的root,所以或者它可以只指向/example-404/内部,我不确定哪个更容易做到。不管怎样,我希望浏览器地址栏中的地址保持不变。
我想要这个的原因是如果http://localhost直接访问服务器将会有一个不同的404页面。我真的很感激任何人对此的想法!
我正在尝试创建以下流baz,其中包含一个“外部”流,其中该流的每个事件也有一个“内部”流。
对于外部流中的每个事件 X,X 的内部流中的所有事件都应添加到baz。
class Foo {\n final StreamController<int> bar = StreamController();\n\n Foo() {\n getsAnOuterStream.listen((event) {\n bar.addStream(getsAnInnerStream(event));\n });\n }\n\n Stream<int> get baz => bar.stream;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n上面的代码按预期工作。然而,我知道我可以通过使用该asyncExpand 方法来简单地实现这一点。
class Foo {\n final Stream<int> baz = getsAnOuterStream\n .asyncExpand((event) => getsAnInnerStream(event));\n}\nRun Code Online (Sandbox Code Playgroud)\n\n当外部流更改时,这不起作用 \xe2\x80\x93,新的内部流事件不会添加到baz. 我在这里缺少什么微妙之处吗?任何帮助深表感谢!
只是要注意...我认为问题可能与此有关:如果内部流永远持续下去,则baz永远不会继续处理下一个内部流中的事件。但是,如果这是问题所在,为什么顶级解决方案有效?
有没有办法只对成功的请求(即 HTTP 状态代码 200)启用速率限制?
例如,在我的配置的以下片段中......
http {
limit_req_zone $binary_remote_addr zone=test:10m rate=2r/m;
server {
location / {
limit_req zone=test;
proxy_pass http://localhost:3000/;
...
}
...
}
...
}
Run Code Online (Sandbox Code Playgroud)
...请求成功速率受到限制(每分钟最多两个请求)。
但是,由于这是用于向我发送电子邮件的联系表单,因此如果返回错误,我不关心速率限制,http://localhost:3000/因为不会发送任何电子邮件。