我有一个子域名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
}
答案1
如果您确实希望graphql
通过另一个端口访问该 URL,则需要有一个单独的server
块:
server {
listen 8080 ssl;
... ssl options ...
location /graphql/ {
proxy_pass http://127.0.0.1:8000;
}
}