我想在我的nginx中为我的鹈鹕博客进行重定向。这是我最初的地址(或者它看起来像......):
/年/月/日/条/
所以对于ex: / 2014/01/07 /一些-制品/
我想要的是,如果nginx找不到任何最后一个子文件夹,它会为父级服务(并继续使用根目录)。
所以在url / 2014/01/07 / some-article /如果它找不到文件夹" some-article"它服务于父文件夹" 07"。但同样,如果它没有找到它,请服务于" 01",然后继续逻辑到年,最后根。
顺便说一句,如果你读了愚蠢的配置,请指教。我从我当前运行的网站上获取了配置,因此对于鹈鹕博客来说可能不准确。现在看起来像配置文件(尚未测试):
server {
listen 443 ssl;
listen 80;
listen [::]:80;
listen [::]:443 ssl;
server_name my.server.com;
root /pelican/;
index index.html;
location / {
rewrite ^/fr/feed/ /fr/feed/rss.xml permanent;
rewrite ^/en/feed/ /en/feed/rss.xml permanent;
rewrite ^/en/ / permanent;
rewrite ^/fr/ / permanent;
try_files $url;
}
# This block will catch static file requests, such as images, css, js
# The : prefix is a "non-capturing" mark, meaning we do not require
# the pattern to be captured into $1 which should help improve performance
location ~* \.(:ico|css|js|gif|jpeg|png)$ {
# Some basic cache-control for static files to be sent to the browser
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
# remove the robots line if you want to use wordpress" virtual robots.txt
location = /robots.txt { access_log off; log_not_found off; }
# this prevents hidden files (beginning with a period) from being served
location ~ /\. { access_log off; log_not_found off; deny all; }
}
答案 0 :(得分:0)
我解决了这件事。
这是我的新配置:
server {
listen 443 ssl;
listen 80;
listen [::]:80;
listen [::]:443 ssl;
server_name xxxxxxxxx;
root /var/www/pelican/;
index index.html rss.xml;
# faillite du nom de l'article
location ~* ^/([0-9]+)/([0-9]+)/([0-9]+)/(.+)/$ {
try_files $uri $uri/ /$1/$2/$3/;
}
# faillite du jour
location ~* ^/([0-9]+)/([0-9]+)/([0-9]+)/$ {
try_files $uri $uri/ /$1/$2/;
}
# faillite du mois
location ~* ^/([0-9]+)/([0-9]+)/$ {
try_files $uri $uri/ /$1/;
}
# faillite de l'annee et des langues
location ~* ^/([0-9]+)/$ {
try_files $uri $uri/ /;
}
}