【问题标题】:How to accept request with port after domain in nginx如何在nginx中接受域后的端口请求
【发布时间】:2021-08-08 23:52:18
【问题描述】:

我有一个子域https://test.shop.com,我正在运行一个 Nginx 服务器,它工作正常。但我必须接受https://test.shop.com:8080/graphql/ 的请求并将http://127.0.0.1:8000 重定向到同一台机器。我已经添加了这个块

    location /graphql/ {
       proxy_pass http://127.0.0.1:8000;
    }

但是当我尝试从浏览器访问https://test.shop.com:8080/graphql/ 时,它显示无法访问此站点似乎与 dns 有关。虽然我可以访问https://test.shop.com/graphql/ 并且工作正常。

我的整个配置文件是

    server {
    server_name test.shop.com;
    root /var/www/html/test;
    index index.html;
    location / {
        try_files $uri $uri/ /index.html?$args;
      }
        # dashboard app
    location /dashboard/ {
        try_files $uri $uri/ /dashboard/index.html?$args;
    }

    location /graphql/ {
       proxy_pass http://127.0.0.1:8000;
    }


    listen [::]:443 ssl; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/test.shop.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/test.shop.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

}
    server {
    if ($host = test.shop.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    listen [::]:80;
    server_name test.shop.com;
    return 404; # managed by Certbot
}

【问题讨论】:

    标签: http nginx https dns ip


    【解决方案1】:

    您必须创建新的虚拟主机并将该虚拟主机监听到端口 8080。

    server {
      listen 8080 ssl;
      server_name test.shop.com;
      root /var/www/html/test;
      index index.html;
    
      location /graphql/ {
        proxy_pass http://127.0.0.1:8000;
      }
    
    
      ssl_certificate /etc/letsencrypt/live/test.shop.com/fullchain.pem; # managed by Certbot
      ssl_certificate_key /etc/letsencrypt/live/test.shop.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
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-10
      • 2018-04-24
      • 1970-01-01
      • 2015-06-28
      • 2015-03-16
      • 1970-01-01
      • 2021-11-12
      • 2019-05-05
      相关资源
      最近更新 更多