我一直在尝试在一个位置服务多个目录,以便所有文件都可以在/ sys / assets / – FILE上访问,而不pipe文件物理位置在以下文件夹中 location /sys { alias /var/www/website_api/sys/public; try_files $uri $uri/ /sys/index.php$is_args$args; location ~ \.php { fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_split_path_info ^(.+\.php)(.*)$; include /etc/nginx/fastcgi_params; } location /sys/assets { alias /var/www/website_api/sys/app/assets/javascripts/; } location /sys/assets { alias /var/www/website_api/sys/app/assets/stylesheets/; } location /sys/assets { alias /var/www/website_api/sys/app/assets/images/; } } 目标: /sys/assets/javascriptFile.js /sys/assets/stylesheetFile.css /sys/assets/image.png
由于各种原因,我们遵循一个内部DNS计划,其中www.test.com的内部testing网站将是“p.test-tst.com.local”。 我不会详细说明为什么我们结束了我们正在使用的计划。 现在,我可以添加“p.test-tst.com.local”,“p.test-tst.de.local”,“p.test-tst.co.uk.local”(等等)到Nginx此特定testing网站的configuration文件。 但是,这样做没有更灵活的方法吗? 我可以以某种方式让Nginx接受'p.test.tst.com.local',并将其内部重写为'www.test.com',以便网站(在Drupal上运行)认为请求是为了' www.test.com“? 其中一个主要的原因就是我不会考虑在语言处理(为'com.local'设置一种语言)时向Drupal添加更多的逻辑。
我如何强制nginx服务自定义的404页面,同时响应404头,而不改变浏览器的地址,以便用户可以轻松地重新键入? set $allowed 0; #(updated after comments) error_page 404 /404page.html; #(updated after first answer, forgot to mention) location = /authreq.html { if ($allowed = 0){ # return 307 $scheme://$host/404page.html ; #works but should be 404 # return 404 "shows this message"; #does not redirect when inserting url instead of message # rewrite ^ /404page.html break; […]
我需要一个.htaccess来显示这个URL: http://www.mysite.com/es/wp-content/plugins/mailpress/mp-includes/action.php?action=mail_link&add=123&lang=es 但实际上会提供这个url: http://www.mysite.com/wp-content/plugins/mailpress/mp-includes/action.php?action=mail_link&add=123&lang=es 请注意,action.php可以接收URL中的其他GET参数。 htaccess也必须能够发挥它们的作用。 这两个URL之间的唯一区别是将反映“lang”GET参数的“假”根目录。 是否有可能用.htaccess做这样的事情(我很确定这是可能的)? 任何人都有指示如何做到这一点? 谢谢! 编辑1:我忘了说重写规则应该只对“/ wp-content / plugins / mailpress / mp-includes /”中的“action.php”有效。 编辑2:我目前在我的.htaccess: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
想像一下三步跳跃的体育赛事,前两步完美到位,第三步跳入空中,永不回头,最终摔倒! 这就是这个问题归结为:) 第1 /somepage?ln=xx :当用户导航到/xx/somepage时,工作服务/somepage?ln=xx 。 # if user inputs nice urls /xx/somepage to serve page /someapge?ln=xx RewriteRule ^([az][az])/(.*) /$2?ln=$1 [L] 第二步:只有在给定语言的情况下才能进入主页/ xx / # if language xx given but no page given? then redirect to its home /xx/home RewriteRule ^([az][az])/?$ /$1/home [R=301,L] 第3步:碰撞 # if user inputs /somepage then redirect to default english: /en/somepage […]
目前所有的名称都指向同一个Web服务器文件夹,这是正确的。 也就是说,domain.net,domain.org等工作,而不redirect到主.com 如何访问.org和.net将浏览器redirect到domain.com? 这应该是基本的,但我无法弄清楚最好的办法。
我正在尝试网站切换。 我们希望通过使用301redirect来保留我们的外部链接。 我在一个命名的位置有一个冗长的redirect列表,类似于: location @redirects { rewrite ^/path/one.html$ http://www.ourdomain.tld/one-but-different permanent; rewrite ^/path/two.html$ http://www.ourdomain.tld/two-but-different permanent; rewrite ^/path/three.html$ http://www.ourdomain.tld/three-but-different permanent; rewrite ^/path/four.html$ http://www.ourdomain.tld/four-but-different permanent; } (请注意,即使看起来我的示例显示了一个模式,但没有模式存在,换句话说,它们是一对一的redirect。) 我有一个CMS Web应用程序,目前我正在使用下面的try_files语句(它一直在努力回落到index.php脚本): location / { try_files $uri $uri/ /index.php; } 现在我试图使用try_files来“查看”redirect的位置,并在返回到index.php之前处理重写。 喜欢这个: location / { try_files @redirects $uri $uri/ /index.php; } 但是,CMS在处理404时每次都会触发回退。 换句话说,如果我尝试使用http://www.ourdomain.tld/path/one.html ,我可以获取我的CMS的404页面而不是redirect! 是否有可能首先“尝试”一个命名的位置,或者命名的位置是否是后备? 我确定我做错了。 不过,有人能指出我的方向吗? nginx的/ 1.2.4 谢谢!
我想获得一个dynamic的404响应取决于请求的url: foo.jpg不存在 http://example.com/img/style/thumbnail/foo.jpg 应该显示 http://example.com/img/notfound/thumbnail.jpg 具有404头状态 我得到了正确的重写部分,但我似乎无法得到它与404状态代码返回。 我用下面的代码尝试了这个,但没有成功: location ~ /img { if (!-f $request_filename){ rewrite "^(.*img\/)style\/([a-zA-Z\_\-[0-9]*)\/?(.+)" $1notfound/$2.jpg; #so far so good. Now i want to return the rewrite result as a 404 response error_page 404 = $request_filename; return 404; } } 这给了我默认的nginx 404错误页面,而不是重写的URL与404状态码。 我如何告诉nginx使用404错误页面的重写结果?
我有两个VPS(一个用于故障转移),都运行Nginx作为后端服务器的负载平衡器。 另外,我已经在Nginx上为我的域(在GoDaddy.com上注册)启用并configuration了SSL。 由于我正在使用DNS Alogging来configurationVPS故障转移的域,因此我无法input端口号(只允许IP号码)。因此,默认情况下域名ping端口80.但ssl侦听端口443。 为此,我在nginx的服务器块中使用rewrite方法,但不适用于POST请求。 虽然它适用于GET请求。 我知道proxy_pass可以与POST请求一起使用,但这不是正确的做法(不安全)。 我应该直接在HTTPS连接上发布请求。 这里是我的nginx conf: upstream tomcat_servers{ least_conn; server 123.45.678.90:8080; server 124.345.78.23:8180; } server { listen 80; server_name thedomain.com; rewrite ^(.*) https://$host$request_uri? permanent; } server { listen 443; server_name thedomain.com; ….ssl config….. location / { proxy_pass http://tomcat_servers; proxy_http_version 1.1; proxy_connect_timeout 30s; proxy_read_timeout 30s; proxy_send_timeout 30s; proxy_next_upstream timeout; proxy_next_upstream error invalid_header […]
早上好。 因为我的客户想要保持一个旧的服务器(运行php-fusion)在一个新的服务器(运行Drupal)相同的域名下运行,我有一个问题。 这可能吗? 而最重要的是,我将如何做到这一点? 旧的服务器URL结构像projectname.domain.com,新服务器的URL结构是domain.com/projectname。 这可能吗? 要并行运行这两个服务器,使用相同的域名 – 但使用不同的URL结构? 谢谢Marco