基本上我想要做的是把请求的URL放入一个variables,然后删除一个字符(如/)并获得一个新的variables。 我试图在URL的末尾实现尾部的斜杠; 这工作,但我想要做的所有文件: location /examplehtmlfile/ { try_files = $uri $uri/ examplehtmlfile.html } 否则,如果我在最后添加一个尾部的斜杠它会产生一个404错误。 所以我想要做的是添加到try_files指令(对于主/位置)是这样的: try_files = $uri $uri/ /$uriwithoutslash.html /$uriwithoutslash.php 谢谢
我有2个域名 exemple.net exemple.com 和很多子域 demo1.exemple.com demo2.exemple.com … demo50.exemple.com 目前我有50块这样的: server { listen 80; server_name demo1.exemple.*; location / { proxy_pass http://127.0.0.1:8081; } } server { listen 80; server_name demo2.exemple.*; location / { proxy_pass http://127.0.0.1:8082; } } 此解决scheme正在工作,但没有真正优化。 我试图“返回”.com而不是.net,以避免“X”冗余,但我不知道如何包含子域有一个variables。 server { server_name *.demo.net; return 301 http://demo.com$request_uri; } 应该有一种方法来尊重nginx的最佳实践,并避免所有这些冗余,但我不知道如何pipe理这个问题。
这是我目前的nginx站点configuration: server { server_name DOMAIN; access_log /srv/www/DOMAIN/logs/access.log; error_log /srv/www/DOMAIN/logs/error.log; root /srv/www/DOMAIN/public_html; location / { if ($request_uri ~ ^/(.*)\.html$) { return 302 /$1; } try_files $uri $uri.html $uri/ @extensionless-php; index index.html index.htm index.php; } location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; if ($request_uri ~ ^/([^?]*)\.php($|\?)) { return 302 /$1?$args; } […]
这是我的nginx站点configuration: server { server_name DOMAIN.COM; access_log /srv/www/DOMAIN.COM/logs/access.log; error_log /srv/www/DOMAIN.COM/logs/error.log; root /srv/www/DOMAIN.COM/public_html; location / { if ($request_uri ~ ^/(.*)\.html$) { return 302 /$1; } try_files $uri $uri/ $uri.html $uri.php?$args; index index.html index.htm index.php; } location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; if ($request_uri ~ ^/([^?]*)\.php($|\?)) { return 302 /$1$is_args$args; } […]
这个redirect添加了一个尾部的斜线,打破了我想要花费的链接,确切的代码如下: server { listen 80; server_name graphwhy.org; return 301 https://www.surveymonkey.com/r/nationaldebt$request_uri; } 目前当有人inputgraphwhy.org到他们的浏览器,他们被redirect到https://www.surveymonkey.com/r/nationaldebt/这个url是不承认。 Survey猴只会认识到https://www.surveymonkey.com/r/nationaldebt 有人可以帮我删除尾部的斜线。 先进的谢谢你。
我的服务器使用nginx,我的域名服务于静态HTML网页,即 http://server.com/download.html 出于各种原因,我希望用户能够通过以下url获取download.html : http://server.com/download.html (works) http://server.com/download (works) http://server.com/download/ (works not) 我得到了前两个工作,但最后一个总是返回/404.html。 try_files能够做我想做的,还是我必须使用rewrite指令呢? 我的nginxconfiguration: location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri.html $uri/ /404.html; # auth_basic "Restricted"; # auth_basic_user_file /var/www/upscaledb/htpasswd; } 谢谢你,克里斯托夫
目前我们正在创造一个新的环境,并且遇到一些与SSL有关的怪癖。 我们正在使用接受80/443的ELB。 两个路由到Nginx盒子上的同一个端口(ELB Decrypts)。 在Nginx框中,我们正在检查AWS头,如果我们没有看到它,我们会redirect到https。 到目前为止,虽然redirect不起作用。 以下是在端口3000(ELB 80-> 3000,ELB 443-> 3000)上监听的站点的nginxconfiguration文件的副本。 server { listen 80; root /home/app/web-app/public; passenger_enabled on; passenger_user app; # If this is a Ruby app, specify a Ruby version: passenger_ruby /usr/bin/ruby2.2; passenger_min_instances 2; if ($http_x_forwarded_proto != "https") { return 301 https://$host$request_uri; } } 任何想法,我在做什么错在这里? 编辑 – 我们正在使用这里看到的客运docker图像 – https://github.com/phusion/passenger-docker 乘客启动,似乎采取端口3000的所有请求,尽pipeNginxconfiguration显示听80。
我遇到了Nginx的一个奇怪的问题。 这是一个重现错误的最小configuration: server { server_name mydomain.com; listen 111.111.111.111:80; root /some/path; set $some_var $sent_http_content_type; add_header "X-Debug" $sent_http_content_type; } 在这种情况下, X-Debug头文件在响应中从不显示。 但是,如果我评论这一行: set $some_var $sent_http_content_type; 一切正常。 这对我来说似乎很奇怪,因为这行不会重新分配$sent_http_content_type var,但只能读取。 它看起来像只属于$sent_http_variables。 我也尝试了"${sent_http_content_type}"而不是$sent_http_content_type ,结果相同。 more_set_headers指令不能解决这个问题。 为什么Nginx的行为如此呢? 这是一个错误? 编辑: 我提供的例子只是最简单的情况,其中$sent_http_ vars消失。 其实我想做这样的事情: if ($sent_http_access_control_allow_origin ~ "^(https?)://([^/]+)") { set $new_cors http://$1.$2.proxy.mydomain.com; } more_set_headers "Access-Control-Allow-Origin: $new_cors"; 我写了一个代理服务器,我需要replaceAccess-Control-Allow-Origin响应头,因为否则代理的网站不能按预期工作。 在上面的例子中, if条件(在server部分)永远不会成true ,即使有这样的头,它适合我的正则expression式。 这可以解决吗? 感谢你的帮助!
我已经安装了munin(暂时可用: http : //brailsford.xyz/munin ),问题是从/ var / cache / munin / www的核心加载 – 无静态文件加载。 我在我的nginxconfiguration中有以下内容: location /munin/static/ { alias /etc/munin/static/; expires modified +1w; autoindex on; } location /munin/ { #auth_basic "Restricted"; # Create the htpasswd file with the htpasswd tool. #auth_basic_user_file /etc/nginx/htpasswd; alias /var/cache/munin/www/; expires modified +310s; } AutoIndex有一个certificate:该文件夹是可访问的: https ://brailsford.xyz/munin/static/ 但是,单击该文件夹中的文件会给出404,而nginx错误日志显示了这一点: [error] 22570#0: *50 […]
如何指定www.domain.com/ru/打开www.domain.com/的内容? 不是redirect。 我已经试过别名和根,但不能如何使其工作。 谢谢。