首页 > 解决方案 > 我应该如何使用 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/,但结果为空白。

如何解决这个问题?

标签: nginxsingle-page-application

解决方案


您不应该使用index和添加try_files

server {

  listen 8081;
  server_name localhost;

  location / {        
    root /var/www/react-app;
    try_files $uri $uri/ /index.html;
  }
}

推荐阅读