【发布时间】:2019-07-03 08:07:03
【问题描述】:
我有一个用 nextjs 编写的现有应用程序,因为我需要 SSR。由于我在管理方面不需要 SSR,我想使用 react-admin。我不打算将两者集成,而是让它们作为单独的进程/服务在单独的端口上运行,并让 nginx 进行代理路由。我在配置 react-admin 时遇到了困难。
- nextjs 在 127.0.0.1:3000 上运行
- react-admin 在 127.0.0.1:3001 上运行
nginx反向代理位置的配置:
server {
server_name www.mydomainname.com;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
location /admin {
proxy_pass http://127.0.0.1:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
# 301 Redirect URLs with trailing /'s
#as per https://webmasters.googleblog.com/2010/04/to-slash-or-not-to-slash.html
rewrite ^/(.*)/$ /$1 permanent;
# 301 redirect from custom redirect file
if ( $redirect_uri ) {
return 301 $redirect_uri;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mydomiainname.com/fullchain.pem # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mydomainname.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
我相信 nginx 配置是正确的。当导航到 /admin 时,react-admin 响应的是一个空白的“React App”页面,而不是从它的根目录“/”路径看到的默认页面。
我尝试在 react-app package.json 文件中设置 'homepage': "/admin" 却没有任何乐趣。
如何配置 react-app 以默认将页面提供给 /admin 而不是 /?
【问题讨论】:
标签: nginx next.js react-admin