我正在运行nginx 0.6.32作为couchdb的代理前端.我在数据库中有我的robots.txt,可以访问http://www.example.com/prod/_design/mydesign/robots.txt.我也有类似网址上动态生成的sitemap.xml.
我试过以下配置:
server {
listen 80;
server_name example.com;
location / {
if ($request_method = DELETE) {
return 444;
}
if ($request_uri ~* "^/robots.txt") {
rewrite ^/robots.txt http://www.example.com/prod/_design/mydesign/robots.txt permanent;
}
proxy-pass http://localhost:5984;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
Run Code Online (Sandbox Code Playgroud)
这似乎是一个重定向,但有一个更简单的方法吗?
Pla*_*own 56
或者你可以简单地把它放在自己的位置 -
location /robots.txt {
alias /Directory-containing-robots-file/robots.txt;
}
Run Code Online (Sandbox Code Playgroud)
dol*_*ols 19
我想你想设置一个位置.关键部分是"="指令.
location = /robots.txt {
alias /your_full_path/robots.txt ;
}
Run Code Online (Sandbox Code Playgroud)
(当我没有包含=时,它仍然转到默认的nginx根位置)
如下设置,将导致所有/robots.txt*请求从/ var/foo中读出.所以/robots.txt.bing试图从磁盘上读取/var/foo/robots.txt.bing."^〜"表示它是请求开头的正则表达式匹配.
location ^~ /robots.txt {
root /var/foo;
}
Run Code Online (Sandbox Code Playgroud)
使用http://重写...打算进行重定向.您可能正在寻找:
rewrite ^/robots.txt /prod/_design/mydesign/robots.txt last;
| 归档时间: |
|
| 查看次数: |
37373 次 |
| 最近记录: |