Php nginx正在尝试指定不同的位置,而不是主根目录

Php nginx正在尝试指定不同的位置,而不是主根目录,php,nginx,Php,Nginx,我有一个处理不同“网站”的配置,一个主根目录处理对主url的请求,我为它指定一个特定路径,在另一个位置/mailtracker中,我处理一个不同的应用程序并将它指向不同的目录。我的问题是php fpm找不到第二个位置 基本上,我希望有几个指向不同根的位置 server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /var/www/sites/dor

我有一个处理不同“网站”的配置,一个主根目录处理对主url的请求,我为它指定一个特定路径,在另一个位置/mailtracker中,我处理一个不同的应用程序并将它指向不同的目录。我的问题是php fpm找不到第二个位置

基本上,我希望有几个指向不同根的位置

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

    root /var/www/sites/dorero/;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
    }

location /mailtracker {
    alias /var/www/sites/mailtracker/web/;
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 192.168.10.3:9000;
                fastcgi_index index.php;
            include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
 }

    location ~ ^/(index|app|app_dev|config)\.php(/|$) {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
    ## NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    #
    #       # With php5-cgi alone:
   fastcgi_pass 192.168.10.3:9000;
    #       # With php5-fpm:
    #   fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    }
我试图指定别名/var/www/sites/mailtracker/web/的路径,而不是$document\u root,但它不起作用

从php fpm到该配置的输出显示:

192.168.10.4 -  06/Feb/2018:19:04:49 +0000 "GET /mailtracker/index.php" 404
  • location/mailtracker
    放在
    location/
    上方,因为在检查
    /mailtracker
    之前,nginx为
    /
    匹配了路由
    /mailtracker
  • 您可以在
    location/mailtracker
  • 添加
    try_文件$uri$uri/=404
    位置/mailtracker
  • 编辑:


    没有工作,我从php fpm中找不到文件。GET/mailtracker/index.php“404有一个index.phpDidn不起作用,我已经试过了,我做错了。nginx将/mailtracker/放在对php fpmSorry的请求中,只是现在我看到了您的编辑,我尝试了上面的配置,主位置/不起作用,403禁止和/mailtracker/没有解释php
    server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
    
        root /var/www/sites;
        index index.php index.html index.htm;
    
        # Make site accessible from http://localhost/
        server_name localhost;
        location @rewriteapp {
               rewrite ^(.*)$ /app.php/$1 last;
        }
    
        location /mailtracker {
            alias /var/www/sites/mailtracker/web;
            set $subfolder "mailtracker/web";
            try_files $uri @rewriteapp;
        }
    
        location / {
                root /var/www/sites/dorero;
                set $subfolder "dorero";
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }
    
    
        location ~ ^/(index|app|app_dev|config)\.php(/|$) {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                ## NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                #
                #       # With php5-cgi alone:
                fastcgi_pass 192.168.10.3:9000;
                #       # With php5-fpm:
                #   fastcgi_pass unix:/run/php/php7.0-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
                fastcgi_param  SCRIPT_FILENAME    $document_root/$subfolder/$fastcgi_script_name;
        }
    }