为两个应用程序配置相同的端口

时间:2019-06-05 07:22:39

标签: nginx

我在Linux上有两个应用程序。其中一个在http://localhost:5000上,第二个在http://localhost:5003上; 我希望来自域xxx.com的所有请求都重定向到https和应用程序:5000, 子域api.xxx.com我想选择:5003。它是我的配置

    server {
        listen 80;
            server_name  api.xxx.com;
        location / {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_pass         http://localhost:5003;
        }
    }

    server {
        listen     80 default_server;
        server_name xxx.com;
        add_header Strict-Transport-Security max-age=15768000;
        return     301 https://$host$request_uri;
    }

    server {
        listen                    *:443 ssl;
        server_name               xxx.com;
        ssl_certificate           /home/piotrekb3/ssl/certs/xxx.crt;
        ssl_certificate_key       /home/piotrekb3/ssl/keys/new_key.key;

        add_header Strict-Transport-Security "max-age=63072000; preload";
        add_header X-Frame-Options DENY;
        add_header X-Content-Type-Options nosniff;

        #Redirects all traffic
        location / {
            proxy_pass         http://localhost:5000;
            limit_req  zone=one burst=10 nodelay;
        }
    }

域xxx.com(:5000)上的应用程序正常运行。但是我对api.xxx.com有问题。它不起作用(主机不可访问)。我该如何配置? 谢谢!

0 个答案:

没有答案