将子域重定向到端口;不起作用

问题描述 投票:0回答:1
server {
        listen         8080 default_server;
        listen         [::]:8080 default_server;
        server_name    cad.domain.tech;
        root           /var/www/cad;
        index          index.php;

          location ~* \.php$ {
            fastcgi_pass unix:/run/php/php7.2-fpm.sock;
            include         fastcgi_params;
            fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
          }
        } 

我在NGINX网站上有此文件,当我执行IP:8080时,我得到了放置在那里的网页。但是,当我执行cad.domain.tech时,出现“找不到服务器”。

以下是我的页面规则和DNS设置:enter image description hereenter image description here

有人有什么想法吗?

nginx dns hosting cloudflare
1个回答
1
投票

这是因为访问http://cad.domain.tech时,它默认情况下在端口80上请求您的服务器(如果请求以https://开头,则为端口443)。

因此,您需要做的就是将端口80上的所有传入请求重定向到端口8080。

server {
    listen 80;
    listen [::]:80;
    hostname cad.domain.tech www.cad.domain.tech;
    return 301 http://cad.domain.tech:8080
}

这应该有效。 return 301告诉请求者这是永久重定向。

© www.soinside.com 2019 - 2024. All rights reserved.