How to accept request with port after domain in nginx
I have a subdomain https://test.shop.com
, I'm running a Nginx server and it's working fine. But I have to accept the request with https://test.shop.com:8080/graphql/
and redirect to http://127.0.0.1:8000
to the same machine. I've added this block
location /graphql/ {
proxy_pass http://127.0.0.1:8000;
}
But when I try to access https://test.shop.com:8080/graphql/
from the browser it shows me This site can’t be reached seems something to do with dns. Although I can access https://test.shop.com/graphql/
and it works fine.
My whole config file is
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
}
Solution 1:
If you really want to have the graphql
URL reachable via another port, you need to have a separate server
block:
server {
listen 8080 ssl;
... ssl options ...
location /graphql/ {
proxy_pass http://127.0.0.1:8000;
}
}