flutter web built release but nginx route 404

xn1cxnb4  于 2023-10-17  发布在  Nginx
关注(0)|答案(2)|浏览(114)

相似案例:flutter-web-app-blank-screen-in-release-mode
AWS EC2云服务器我在我的EC2服务器上构建了一个flutter web构建。并将flutter web index.html交叉连接到Nginx。

> $ flutter build web

💪 Building with sound null safety 💪

Compiling lib/main.dart for the Web...                           1,491ms

所以EC2可以是200。

然后导航到另一个页面并刷新。

我的EC2服务器nginx配置是:

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/flutter_web_project/build/web; # <- the flutter build web released result folder

        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                try_files $uri $uri/ =404;
        }
}

使用url_strategy dependency

dependencies:
  flutter:
    sdk: flutter

    url_strategy: ^0.2.0

main.dart源代码:

...
import 'package:url_strategy/url_strategy.dart';

void main() {
  setPathUrlStrategy();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'flutter web sample',
      theme: ThemeData(
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: locationPlatform(),
      onGenerateRoute: WebRouter.generate,
      initialRoute: '/',
    );
  }
...
oyjwcjzk

oyjwcjzk1#

更新nginx配置它将用于直接URL。

location / {
    try_files $uri $uri/ /index.html;
 }
falq053o

falq053o2#

更新nginx配置它将用于直接URL。

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

在以下行添加注解:

# include /etc/nginx/conf.d/*.conf;

相关问题