簡體   English   中英

如何在 nginx 中接受域后端口的請求

[英]How to accept request with port after domain in nginx

我有一個子域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/時,它向我顯示無法訪問此站點似乎與 ZB3BF60B851EBAEB22368B01A32E2 有關。 雖然我可以訪問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
}

您必須創建新的虛擬主機並將該虛擬主機監聽到端口 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

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM