首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >前端后端通信

前端后端通信
EN

Stack Overflow用户
提问于 2018-03-31 10:24:43
回答 1查看 1.4K关注 0票数 0

我有两个应用程序运行在端口8000 (本地)和react 3000(本地)上的ASW Symfony上,但是通过端口80的TCP访问重定向是通过侦听nginx服务器中的端口80来实现的。

代码语言:javascript
运行
复制
server {
    listen 80;
    server_name example.info  www.example.info;
    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;
     }
}
server {
    listen 8000;
    server_name example.info  www.example.info;
    location / {
        proxy_pass http://127.0.0.1:8000;
        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;
     }

}

我试着监听和重定向两个端口,但都没有成功。在服务器内部,Symfony应用程序可以从外部使用curl http://127.0.0.1:8000访问,我正在向asw.external.ip发送api请求(123.123.123.123:800),但我会超时。我怎么能从外面进入我的后端呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-31 21:10:01

AWS ElasticBeanstalk -将代理服务器配置到后端

您也可以将此配置文件用于Aws Ec2。

/etc/nginx/con.d/proxy.conf

代码语言:javascript
运行
复制
  upstream nodejs {
    server 127.0.0.1:5000;
    keepalive 256;
  }

  server {
    listen 8080;

    access_log  /var/log/nginx/access.log  main;

    location / {
        proxy_pass  http://nodejs;
        proxy_set_header   Connection "";
        proxy_http_version 1.1;
        proxy_set_header        Host            $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    gzip on;
    gzip_comp_level 4;
    gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    ## Optional configuration if you want to allow AWS 
    ## to cache your static files
    location /static {
        alias /var/app/current/static;
    }
  }

编辑-为Symfony配置Nginx

代码语言:javascript
运行
复制
server {
    listen             8080;
    server_name        sf2testproject.dev;

    root /home/maurits/public_html/web;

    location / {
        # try to serve file directly, fallback to rewrite
        try_files $uri @rewriteapp;
    }

    location @rewriteapp {
        # rewrite all to app.php
        rewrite ^(.*)$ /app.php/$1 last;
    }

    location ~ ^/(app|app_dev|config)\.php(/|$) {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS off;
    }
}

其中:

  • listen是您的应用程序与世界通信的端口。
  • fastcgi_pass是一种二进制协议,用于将交互式程序与web服务器连接起来。

参考文献:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49586717

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档