我对Nginx还不熟悉,所以请耐心等待。在
我试图将所有请求从一个子目录(store)重定向到另一个子目录(trade)的根目录。请看下面我的进度。目标子目录(trade)中的站点是一个magento站点,因此这是当前大多数规则的用途
server {
server_name example.com *.example.com;
root /usr/share/nginx/html/example.com/public_html;
index index.php index.html index.htm;
access_log /var/log/nginx/example.access.log;
error_log /var/log/nginx/example.error.log;
location / {
try_files $uri $uri/ /index.html;
}
location /trade/ {
index index.html index.php;
try_files $uri $uri/ @handler;
expires 30d;
}
location ~ /store {
rewrite /trade permanent;
}
location ~ ^/trade/(app|includes|lib|media/downloadable|pkginfo|report/config.xml|var)/ { internal; }
location /trade/var/export/ { internal; }
location /. { return 404; }
location @handler { rewrite / /trade/index.php; }
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
我用于重定向的部分如下:
location ~ /store {
rewrite /trade permanent;
}
这对example.com/store但不是示例/存储/索引.php或任何其他带参数的uri。我有一种感觉,底部的php文件部分覆盖了处理过程。这就是为什么我把~放在商店前面作为文件here声明将首先处理此项。还是继续处理?在
我读过关于嵌套一个php规则的文章,但是我尝试过没有用
我将非常感谢你的帮助