【问题标题】:Redirecting a subdomain to a port; not working将子域重定向到端口;不工作
【发布时间】:2020-02-23 00:13:33
【问题描述】:
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 设置:

有人有什么想法吗?

【问题讨论】:

    标签: nginx dns hosting cloudflare


    【解决方案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 告诉请求者这是一个永久重定向。

    【讨论】:

      猜你喜欢
      • 2014-05-17
      • 2014-07-02
      • 2016-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多