流明:使用nginx在子页面下托管路由问题

问题描述

我使用lumen框架编写了小型应用程序。现在,我正在尝试使用Nginx将其托管在ubuntu服务器上。 其背后的全部想法是让该应用程序可在子页面下访问。因此,假设在地址http://example.com下将提供一些静态HTML页面,并在http://example.com/voodoo流明应用程序下。我几乎可以正常工作,但是我必须编辑流明路由并在我的路由配置中添加/voodoo前缀。这是我要避免的事情。

这是我当前的Nginx配置,不起作用:

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

root /var/www/voodoo/public;
index index.PHP index.html index.htm;

server_name example.com;
charset   utf-8;

gzip on;
gzip_vary on;
gzip_disable "msie6";
gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types
    text/plain
    text/css
    text/js
    text/xml
    text/javascript
    application/javascript
    application/x-javascript
    application/json
    application/xml
    application/xml+RSS;

location  /voodoo {
    alias var/www/voodoo/public;
    index   index.PHP index.html index.html;
    try_files  $uri $uri/  @nested;

    location ~ \.PHP$ {
        fastcgi_pass unix:/var/run/PHP/PHP7.4-fpm.sock;
        #fastcgi_split_path_info ^(.+\.PHP)(/.+)$;
        include fastcgi.conf;
        fastcgi_index   index.PHP;
        fastcgi_param  SCRIPT_FILENAME  $request_filename;
        #include        fastcgi_params;
     }
 }

location @nested {
    rewrite /voodoo/(.*)$ /index.PHP?/$1 last;
}

location ~ \.PHP$ {
    fastcgi_split_path_info ^(.+\.PHP)(/.+)$;
    fastcgi_pass unix:/var/run/PHP/PHP7.4-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;
}

location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|svg|woff|woff2|ttf)\$ {
  expires 1M;
  access_log off;
  add_header Cache-Control "public";
}

location ~* \.(?:css|js)\$ {
  expires 7d;
  access_log off;
  add_header Cache-Control "public";
}

location ~ /\.ht {
    deny  all;
}

}

使用此配置,当我尝试访问http://example.com/voodoo/api/method-one之类的URL时,由于NotFoundHttpException URL部分无法被内腔识别,所以我得到voodoo

我做错了什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)