我使用的是Go Router
,它在开发模式下运行得非常好。在/
下启动Web应用程序或使用/abc/def?var
刷新也可以。当我使用flutter build web
构建应用程序并在docker容器中启动nginx时,当我请求根目录以外的目录时,会得到404。
main.dart:
final GoRouter _router = GoRouter(
initialLocation: '/me',
errorBuilder: (context, state) {
return const Page404();
},
routes: <RouteBase>[
GoRoute(
name: 'root',
path: '/:tabid',
builder: (BuildContext context, GoRouterState state) {
return NavBarPage(tabId: state.params['tabid']!);
},
routes: <RouteBase>[
GoRoute(
name: 'blog',
path: ':blogid/:title',
builder: (BuildContext context, GoRouterState state) {
return BlogDefault(blogId: state.params['blogid']!);
},
),
],
),
],
);
停靠文件:
FROM ubuntu:22.10 as builder
# Setup standard utils
RUN apt-get update && apt-get install -y unzip xz-utils git openssh-client curl && apt-get upgrade -y && rm -rf /var/cache/apt
# Setup flutter & configure web sdk
RUN git clone https://github.com/flutter/flutter.git /usr/local/flutter
ENV PATH="/usr/local/flutter/bin:/usr/local/flutter/bin/cache/dart-sdk/bin:${PATH}"
RUN flutter config --enable-web
# release build of web app
WORKDIR /usr/src/app
COPY . ./
RUN flutter pub get
RUN flutter build web
FROM nginx:1.23.3-alpine as runtime
COPY --from=builder usr/src/app/build/web /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
nginx.conf
user nginx;
worker_processes auto;
pid /run/nginx.pid;
http {
server {
listen 80;
root /usr/share/nginx/html;
location / {
try_files $uri $uri/ /index.html;
}
}
}
1条答案
按热度按时间hgb9j2n61#
我把nginx.conf复制到了错误的文件夹中。感谢这个问题,我在这里问了我的问题后才发现:try_files in nginx.conf not working
下列
default.conf
在位置/etc/nginx/conf.d/
中工作