【问题标题】:map subdomain to different applications running on same IP same port distingushed by path将子域映射到在同一个 IP 上运行的不同应用程序 同一个端口,由路径区分
【发布时间】:2022-05-06 21:25:12
【问题描述】:

我有 3 个应用程序(一个 Web 应用程序,2 个 Angular 应用程序)在同一个端口 (8080) 上的同一个 ec2 实例上运行 应用程序的路径是

  1. http://53.233.23.12:8080/Abc
  2. http://53.233.23.12:8080/Xyz
  3. http://53.233.23.12:8080/Pqr

我在服务器中使用 Nginx 进行重定向 我的 nginx.conf 文件是这样的`

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
   include /usr/share/nginx/modules/*.conf;

events {
        worker_connections 1024;
      }
http{
       log_format  main  '$remote_addr - $remote_user [$time_local] 
    "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

access_log  /var/log/nginx/access.log  main;
sendfile            on;
tcp_nopush          on;
tcp_nodelay         on;
keepalive_timeout   65;
types_hash_max_size 2048;

include             /etc/nginx/mime.types;
default_type        application/octet-stream;

include /etc/nginx/conf.d/*.conf;

index   index.html index.htm;

server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    include /etc/nginx/default.d/*.conf;
    server_name www.listmydebt.com listmydebt.com;
    return 301  http://listmydebt.com:8080/Abc;


    # redirect server error pages to the static page /40x.html
    error_page 404 /404.html;
        location = /40x.html {
    }

    # redirect server error pages to the static page /50x.html
    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }

 }
    server {
        listen 80;
        server_name admin.listmydebt.com;
        return 301  http://listmydebt.com:8080/Xyz;
    }
     server {
        listen 80;
        server_name partner.listmydebt.com;
        return 301  http://listmydebt.com:8080/Pqr;
    }
  }

所有域和子域(listmydebt.com、admin.listmydebt.com、partner.listmydebt.com)指向相同的 IP 地址(53.233.23.12)。 我的 Nginx 在端口 80 上运行,而我的应用程序在其中部署的 tomcat 服务器在端口 8080 上运行

当我将 listmydebt.com 重定向到 http://listmydebt.com:8080/Abc 时,浏览器 URL 已更改(http://listmydebt.com:8080/Abc)。但我想要的是浏览器上的 url 应该与 listmydebt.com 相同,但它应该显示重定向的 url content.same 也发生在子域中。

请帮帮我。如果需要任何其他信息,请提及。提前致谢。

【问题讨论】:

  • 您正在描述反向代理的功能。调查proxy_pass directive
  • @Satyajit 你终于找到解决方案了吗?

标签: nginx amazon-ec2 proxy tomcat7 reverse-proxy


【解决方案1】:

最好的方法是使用 docker swarm,或者至少将应用程序作为多个端口中的多个 docker 运行。 然后,您可以使用 ansible playbook 轻松映射子域上的端口。

【讨论】:

    猜你喜欢
    • 2020-10-26
    • 1970-01-01
    • 1970-01-01
    • 2014-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多