我在我的网站上的url已嵌套由encodeURI函数编码的url。
www.site.com/http%3A%2F%2Fwww.site.com%2F
我的网站正在运行使用nginx 0.8.53问题是,当nginx得到这样的url,它解码整个url,并删除双斜杠传递不正确的url到乘客,然后在我的ruby代码。 这是我的一般nginxconfiguration:
daemon off; user www-data; pid /var/run/nginx.pid; worker_processes 1; events { worker_connections 1024; } http { passenger_root /usr/local/rvm/gems/ruby-1.9.2-p136@global/gems/passenger-3.0.2; passenger_ruby /usr/local/rvm/wrappers/[email protected]/ruby; include mime.types; default_type application/octet-stream; sendfile on; tcp_nodelay on; gzip on; keepalive_timeout 65; server { listen 80; server_name localhost; log_format combined-realip '$remote_addr ($http_x_real_ip) - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"'; access_log /opt/nginx/logs/access.log combined-realip; if (-f /home/site.com/current/maintenance) { return 503; } root /home/site.com/current/public; passenger_enabled on; rack_env production; passenger_set_cgi_param SERVER_NAME $http_host; error_page 503 /503.html; location = /503.html { root html; } include /home/site.com/current/*nginx.conf; } }
我尝试在/home/site.com/current/nginx.conf中设置merge_slashesclosures
merge_slashes off;
但它没有工作。 我没有任何想法,除了启动乘客作为独立,并使用proxy_pass,但另一个问题是,我使用提供nginx和乘客的云服务,我只能编辑/home/site.com/current/nginx.conf没有别的。
请帮帮我。
当该服务器是默认服务器时,merge_slashes 仅作为服务器块中的指令 。 在http块中指定它。
但是请注意,即使closures了merge_slashes,nginx仍然会解码斜线, Passenger仍然会合并它们。 我在我的网站上通过在我的操作中查找诸如“http:/”之类的东西并且适当地修改它们来解决这个问题:
missing_double_slash_match = /\A([az]+)\:\/([^\/])/.match(term) if !missing_double_slash_match.nil? term = term.sub(missing_double_slash_match[0], "#{missing_double_slash_match[1]}://#{missing_double_slash_match[2]}") end