Laravel由nginx在docker中提供服务,只显示起始页

cx6n0qe3  于 2023-02-25  发布在  Nginx
关注(0)|答案(1)|浏览(240)

所以在docker-compose.yml中我有这2个条目:

nginx:
      image: nginx
      volumes:
      - ./app:/var/www/html:delegated
      - ./config/nginx/default.conf:/etc/nginx/conf.d/default.conf
      ports:
        - "444:444"
      depends_on:
        - laravel
  laravel:
      image: php:8-fpm
      volumes:
        - ./app:/var/www/html:delegated
      ports:
        - "4444:4444"

nginx的配置文件如下所示:

server {
    index index.php;
    listen 444 ssl;
    server_name local.myapp;
    root /var/www/html/public;
    ssl_certificate     /root/ssl/certificate.pem;
    ssl_certificate_key /root/ssl/key.pem;
    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers         HIGH:!aNULL:!MD5;
    location ~ [^/]\.php(/|$) {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        root /var/www/html/public;
        fastcgi_pass laravel:4444;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_read_timeout 900s;
        include        fastcgi_params;
    }
}

当我转到https://local.myapp:444时,我可以根据app/routes/web.php中指定的路径看到laravel的起始页:

Route::get('/', function () {
    return view('welcome');
});

然而,有了这个:

Route::get('/wel', function () {
    return view('welcome');
});

当我转到“https://local.myapp:444/wel“时,结果是“404未找到”。
一定是default.conf中的某个地方出错了,但我看不出是什么。

dgtucam1

dgtucam11#

增加:

location / {
     try_files $uri $uri/ /index.php$is_args$args;
}
location ~ [^/]\.php(/|$) {
    try_files $uri /index.php =404;

成功了。

相关问题