【发布时间】:2021-07-12 07:54:18
【问题描述】:
我正在尝试使用 nginx 部署我的 create-react-app 的静态构建。我已经添加了homepage: ".",这是必需的。
而且最后的输出还是很不错的,只是我不能直接访问一些网址。
我正在使用 react-router-dom 和 react-admin:
在index.js:
<BrowserRouter>
<Switch>
<Route exact path="/">
<Redirect to="/home"/>
</Route>
<Route path="/login" component={LoginComponent}/>
<Route path="/home" component={HomeComponent}/>
<Route path="*">
<Redirect to={"/login"}/>
</Route>
</Switch>
</BrowserRouter>
HomeComponent里面有react-admin,也很简单:
<Admin
dataProvider={myDataProvider}
authProvider={myAuthProvider(this.props)}
layout={MyLayout}>
<Resource title="Users" name="users" list={UserList}/>
<Resource title="Transactions" name="transactions" list={TransactionList}/>
</Admin>
但是当我尝试直接点击该 URL 时:
我的nginx.conf 文件很简单:
root@ubuntu-s-1vcpu-1gb-blr1-01:/etc/nginx# cat nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
location / {
error_page 404 =200 /index.html;
}
【问题讨论】:
标签: reactjs nginx react-router-dom react-admin