根目录/var/www/esn/web/index.php有api,还有一个root /var/www/esn-frontend/build/index.html的页面 .
任务:路由Nginx,以便通过链接sitename.com/在同一个域(不使用子域),它将提供页面/var/www/esn-frontend/build/index.html,并在sitename.com/上api URL给出了/var/www/esn/web/index.php . 我尝试了几个选项,但没有一个没有给出预期的结果 .
server{
listen 8800;
server_name 46.101.117.134;
location / {
root /var/www/esn-frontend/build/;
index index.html;
}
location /api {
root /var/www/esn/web;
try_files $uri $uri/ /index.php$is_args$args;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
try_files $uri =404;
}
}
}
这些链接没有帮助:
nginx configuration with multiple location blocks