我知道有很多類似的問題,但我嘗試了幾種解決方案,但找不到正確的解決方案。 我不知道nginx。我只有一個簡單的任務:在一個具體應用/網站中將所有地址/backend.php/*
重定向到/backend.php
。我用*
來表達任何東西。現在將/backend.php/*
路徑重定向到/index.php
。重定向到nginx
這是我的配置文件:
server {
server_name _;
rewrite^$scheme://mysite.com$request_uri redirect;
}
upstream md {
#this should match value of "listen" directive in php-fpm pool
server unix:/var/run/md.php5-fpm.sock;
}
server
{
server_name .mydomain.eu .mydomain.du;
access_log /var/log/nginx/mydomain.access.log;
error_log /var/log/nginx/mydomain.error.log;
root /home/md/;
include conf/restrictions.conf;
include conf/wordpress.conf;
# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ \.php$ {
# Zero-day exploit defense.
# http://forum.nginx.org/read.php?2,88845,page=3
# Won't work properly (404 error) if the file is not stored on this server, which is entirely possible with php-fpm/php-fcgi.
# Comment the 'try_files' line out if you set up php-fpm/php-fcgi on another machine. And then cross your fingers that you won't get hacked.
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# fastcgi_intercept_errors on;
fastcgi_pass md;
}
}
======= =========== UPDATE
的conf/wordpress.conf:
# WordPress single blog rules.
# Designed to be included in any server {} block.
# This order might seem weird - this is attempted to match last if rules below fail.
# http://wiki.nginx.org/HttpCoreModule
location/{
try_files $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# Directives to send expires headers and turn off 404 error logging.
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off; log_not_found off; expires max;
}
# Uncomment one of the lines below for the appropriate caching plugin (if used).
#include global/wordpress-wp-super-cache.conf;
#include global/wordpress-w3-total-cache.conf;
## Pass all .php files onto a php-fpm/php-fcgi server.
#location ~ \.php$ {
# # Zero-day exploit defense.
# # http://forum.nginx.org/read.php?2,88845,page=3
# # Won't work properly (404 error) if the file is not stored on this server, which is entirely possible with php-fpm/php-fcgi.
# # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on another machine. And then cross your fingers that you won't get hacked.
# try_files $uri =404;
#
# fastcgi_split_path_info ^(.+\.php)(/.+)$;
# #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# include fastcgi_params;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
## fastcgi_intercept_errors on;
## fastcgi_pass wp-php;
#}
什麼是conf/wordpress.conf'''? – amenadiel
問題已更新 – Mariusz
我沒有看到你在哪裏試圖將backend.php/*重定向到backend.php。另外,爲什麼你需要重寫/ wp-admin。 – amenadiel