nginx - 我应该如何使用 Nginx 进行以下操作?
问题描述
我正在尝试使用 Nginx 运行我的反应应用程序。
我创建了我的应用程序的构建(名称:react-app)并将其放置在此处/var/www/react-app
。
然后我创建了一个conf文件/etc/nginx/conf.d/react-app.conf
server {
listen 8081;
server_name localhost;
location / {
root /var/www/react-app;
index index.html index.html;
}
}
include /etc/nginx/conf.d/*.conf;
里面有/etc/nginx/nginx.conf
。
然后我跑过去nginx
打开http://localhost:8081/,但结果为空白。
如何解决这个问题?
解决方案
您不应该使用index
和添加try_files
:
server {
listen 8081;
server_name localhost;
location / {
root /var/www/react-app;
try_files $uri $uri/ /index.html;
}
}
推荐阅读
- javascript - React Native 弹出菜单 - 右上角样式
- ansible - Ansible DellOS6 配置备份
- ecm - vpn ibm-cloud 无法通过 VPN 访问私有地址
- mongodb - 访问声明的类中的静态方法
- java - 如何在具有最终字段的抽象类上使用 Lombok @SuperBuilder
- node.js - amazon-s3 上传失败,无法循环上传文件
- vb.net - 使用 EMGU 从网络摄像头保存图片
- wordpress - 从前端特色图像和 ACF 创建 WordPress 帖子
- vue.js - Vuetify VTooltip 仅在激活器单击时触发
- angular - 在 Angular 中安装 Tesseract.js 后找不到名称“缓冲区”错误