Py学习  »  NGINX

nginx反向代理到nextjs和react admin

brad12s • 5 年前 • 1664 次点击  

我有一个用nextjs编写的应用程序,因为我需要ssr。因为我不需要在管理方面的SSR,所以我想使用react admin。我并不打算集成这两个,而是让它们作为单独的进程/服务在单独的端口上运行,并让nginx做代理路由。我在配置React Admin时遇到困难。

  • NEXTJS运行于127.0.0.1:3000
  • 在127.0.0.1:3001上运行React Admin

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应用程序,使其默认为/admin而不是/?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/30749
 
1664 次点击  
文章 [ 1 ]  |  最新文章 5 年前
Nikolas Stevenson-Molnar
Reply   •   1 楼
Nikolas Stevenson-Molnar    5 年前

react-admin /admin / proxy_pass

location /admin {
    proxy_pass http://127.0.0.1:3001/;
    ...
}

proxy_pass

location /name/ {
    proxy_pass http://127.0.0.1/remote/;
}

location /some/path/ {
    proxy_pass http://127.0.0.1;
}