nginx-设置React App和Flask具有不同的端口号码

发布于 2025-01-22 12:45:34 字数 2138 浏览 3 评论 0原文

我有一个react应用程序可以在

www.domain.io:3000

烧瓶API在

中 运行当导航到 www.domain.io 时,将显示React应用程序。 href =“ http://www.domain.io:5000” rel =“ nofollow noreferrer”> www.domain.io:5000 。

我如何设置nginx服务器块,以便React App和Blask API可以在

这是我的服务器块

ssl_certificate /etc/letsencrypt/live/twitterlicious.io/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/twitterlicious.io/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

server{
        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name twitterlicious.io www.twitterlicious.io;

        proxy_set_header Host $host;
         proxy_set_header X-Forwarded-For $remote_addr;

        location / {
                proxy_pass http://localhost: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;
        }


        listen [::]:443 ssl ipv6only=on; # managed by Certbot
        listen 443 ssl; # managed by Certbot

}

server {
        listen 5000;
        location /{
                proxy_pass http://localhost:5000;
        }
}

server {
    if ($host = www.twitterlicious.io) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = twitterlicious.io) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80 default_server;
        listen [::]:80 default_server;

        server_name twitterlicious.io www.twitterlicious.io;
    return 404; # managed by Certbot

}

任何帮助。谢谢!

I have the react app to run on

www.domain.io:3000

And the Flask API is running on

www.domain.io:5000

The React app is shown when navigated to www.domain.io, but it's having trouble talking to the API on www.domain.io:5000.

How can I set the NGINX server block so the React app and Flask API can co-exist under www.domain.io?

Here is my server block

ssl_certificate /etc/letsencrypt/live/twitterlicious.io/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/twitterlicious.io/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

server{
        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name twitterlicious.io www.twitterlicious.io;

        proxy_set_header Host $host;
         proxy_set_header X-Forwarded-For $remote_addr;

        location / {
                proxy_pass http://localhost: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;
        }


        listen [::]:443 ssl ipv6only=on; # managed by Certbot
        listen 443 ssl; # managed by Certbot

}

server {
        listen 5000;
        location /{
                proxy_pass http://localhost:5000;
        }
}

server {
    if ($host = www.twitterlicious.io) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = twitterlicious.io) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80 default_server;
        listen [::]:80 default_server;

        server_name twitterlicious.io www.twitterlicious.io;
    return 404; # managed by Certbot

}

Any help is appreciated. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文