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

时间:2020-08-29 18:18:39

标签: laravel nginx lumen

我使用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

我做错了什么?

0 个答案:

没有答案