nginx将所有php请求重定向到域根文件夹
我已经有了FreeBSD8SRV和nginx、php、mysql、phpBB论坛、本地extjs应用程序、bugzilla、joomla和PhpMyAdmin(/pma) 问题是当我进入pma并通过登录时,我被重定向到domain_name/index.php?令牌。。。而不是/domain\u name/pma/index.php?令牌。。。 当我登录到joomla管理部分(domain_name/administration/index.php.重定向到domain_name/index.php)时也会发生同样的事情 我知道这可能是一个位置配置问题,但我无法找到它在哪里。 配置如下:nginx将所有php请求重定向到域根文件夹,nginx,Nginx,我已经有了FreeBSD8SRV和nginx、php、mysql、phpBB论坛、本地extjs应用程序、bugzilla、joomla和PhpMyAdmin(/pma) 问题是当我进入pma并通过登录时,我被重定向到domain_name/index.php?令牌。。。而不是/domain\u name/pma/index.php?令牌。。。 当我登录到joomla管理部分(domain_name/administration/index.php.重定向到domain_name/index.p
user www;.
worker_processes 4;
pid /var/run/nginx.pid;
error_log /var/log/nginx-error.log warn;
events {
worker_connections 1024;
use kqueue;
}
http {
gzip on;
gzip_static on;
gzip_vary on;
gzip_http_version 1.1;
gzip_min_length 700;
gzip_comp_level 6;
gzip_disable "msie6";
include mime.types;
default_type application/octet-stream;
# log options.
log_format main '$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$gzip_ratio"';
# nginx options
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
server_tokens off;
# fastcgi
fastcgi_intercept_errors on;
# virtual server
server {
listen 80;
server_name domain_name www.domain_name;
server_name_in_redirect off;
rewrite 301 http://domain_name$request_uri;
access_log /var/log/haim_access_log main;
error_log /var/log/haim_error_log error;
root /usr/local/www;
# phpBB: Support Clean (aka Search Engine Friendly) URLs
location / {
try_files $uri $uri/ /index.php?$args;
}
# Joomla: caching of files
location ~* \.(ico|pdf|flv)$ {
expires 30d;
}
location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)$ {
expires 14d;
}
# Joomla: deny running scripts inside writable directories
location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
return 403;
error_page 403 /403_error.html;
}
# error pages 40x
error_page 404 /40x.html;
location = /nginx-distr/40x.html {
}
# phpBB 3 forum config
location /forum {
}
# phpBB 3: Deny access to internal phpbb files.
location ~ /(config\.php|common\.php|includes|cache|files|store|images/avatars/upload) {
root /usr/local/www/forum;
deny all;
# deny was ignored before 0.8.40 for connections over IPv6.
# Use internal directive to prohibit access on older versions.
# internal;
}
# phpMyAdmin
location ~ /pma4/(.*\.php)$ {
root /usr/local/www/pma4;
index index.php;
fastcgi_pass localhost:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/local/www/pma4/$1;
fastcgi_param DOCUMENT_ROOT /usr/local/www/pma4;
}
# bugzilla
location ~ ^/bugzilla/(.*\.cgi) {
fastcgi_pass unix:/var/run/fcgiwrap/fcgiwrap.sock;
fastcgi_param SCRIPT_FILENAME /usr/local/www/bugzilla/$1;
fastcgi_param DOCUMENT_ROOT /usr/local/www/bugzilla;
include fastcgi_params;
}
# php
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
# cgi
location ~ [^/]\.cgi(/|$) {
fastcgi_pass unix:/var/run/fcgiwrap/fcgiwrap.sock;
fastcgi_index index.cgi;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}
# phpBB: Deny access to version control system directories.
location ~ /\.svn|/\.git {
deny all;
}
# Original: block access for .htpasswd
location ~ /\.ht {
deny all;
}
}
}
这种配置应该会有所帮助
location /pma4 {
root /usr/local/www;
index index.php;
location ~ .*\.php$ {
fastcgi_pass localhost:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/local/www/pma4/$1;
fastcgi_param DOCUMENT_ROOT /usr/local/www;
}
}
几天后,我终于找到了这个问题的真正解决方案,我在这里分享,因为这个帖子在谷歌搜索中仍然有很高的优先级 如链接上所述: 要解决此问题,您应该将以下代码块添加到您的nginx默认站点中。如果可用,您将使用:
sudo nano /etc/nginx/sites-available/default
区块:
# Phpmyadmin Configurations
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
#fastcgi_pass 127.0.0.1:9000;
#fastcgi_param HTTPS on; # <-- add this line
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
# Dealing with the uppercased letters
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
#Phpmyadmin配置
位置/phpmyadmin{
root/usr/share/;
index.php index.html index.htm;
位置~^/phpmyadmin/(.+\.php)${
try_files$uri=404;
root/usr/share/;
#fastcgi_pass 127.0.0.1:9000;
#fastcgi_param HTTPS on;#具体一点,只发布特定代码。我发布了完整的nginx.conf,因为我一直在逐一评论每个部分,试图找出可能导致问题的原因,但运气不佳。因此我认为发布整个代码会更充分。特定服务器/虚拟机的配置文件中有哪些内容主机?(例如站点可用/默认(或在可用站点中使用的任何配置文件)。很可能是文档的根目录有问题。我想最后一行try\u files$uri$uri//index.php?$args;
会将任何查询重定向到根文件夹的index.php,如果确切的url不存在。是否要添加说明,到底什么不起作用?首先,您忘记了}最后,在那之后,我得到了错误“对nginx配置执行健全性检查:nginx:[emerg]pcre_compile()失败:在/usr/local/etc/nginx/nginx.conf中的“hp$”处的“*\php$”中的\P或\P之后的未知属性名称:113 nginx:configuration file/usr/local/etc/nginx/nginx.conf测试失败”修复了这个问题,但仍然被重定向到domain_name/index.php