nginx将所有php请求重定向到域根文件夹

时间:2013-12-06 12:04:54

标签: nginx

我有nbsx,php,mysql,phpBB论坛,本地extjs应用程序,bugzilla,joomla和PhpMyAdmin(/ pma)的Freebsd 8 srv 问题是当我去pma并登录时,我被重定向到domain_name / index.php?token ...而不是/domain_name/pma/index.php?token ... 当我登录joomla admin part(domain_name / administraton / index.php。重定向到domain_name / index.php)时发生同样的事情 我知道这可能是位置配置问题,但我无法找到它的位置。 配置如下:

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;
    }

 }
}

2 个答案:

答案 0 :(得分:0)

此配置应该有帮助

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;
    }
}

答案 1 :(得分:0)

经过几天在键盘上砸我的头后,我终于找到了解决这个问题的真正解决方案,我在这里分享,因为这个帖子在谷歌搜索中仍然具有高优先级。

如链接所述:http://www.samundra.com.np/use-phpmyadmin-with-nginx-and-php7/1374

要解决此问题,您应该将以下代码块添加到您的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;
   }

我希望有一天能帮到某人......