与nginx具有相同域的两个php根目录

时间:2019-03-01 14:50:52

标签: nginx

我正在处理的应用程序有一个用于API后端的index.php文件和一个用于加载前端的index.php。他们使用相同的域,我正在尝试使用nginx进行配置,但是我似乎无法指向index.php位置的/api

我的文件位于/home/vagrant/markus/apps/core/dist/index.php/home/vagrant/markus/api/public/index.php

以下是我的nginx文件:

server {
    listen 80;
    server_name *.testing.laravel;

    root /home/vagrant/markus/apps/core/dist;
    index index.php;

    charset utf-8;

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    rewrite_log on;
    access_log off;
    error_log  /var/log/nginx/app1.testing.laravel-error.log notice;

    sendfile off;

    client_max_body_size 100m;

    location / {
        try_files $uri $uri/ /index.php;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
    }

    location ~ ^/ping {
        allow all;
        add_header Content-Type text/plain;
        return 200 '"pong"';
    }

    location /api {
        rewrite ^/api/(.*) /$1  break;
        root /home/vagrant/markus/api/public/;
        try_files /index.php?$query_string =404;
    }

    location ~ /\.ht {
        deny all;
    }
}

我尝试将root更改为alias。我尝试使用/home/vagrant/markus/作为根,并在两个位置目录中直接将/api/public/apps/core/dist用作根,并直接添加到try_files语句中,但是似乎没有什么可以使我朝正确的方向前进。 / p>

解决此问题的正确方法是什么?

0 个答案:

没有答案
相关问题