【问题标题】:How to setup a custom local domain name for a Node app similar to laravel valet?如何为类似于 laravel valet 的 Node 应用程序设置自定义本地域名?
【发布时间】:2018-10-06 00:36:49
【问题描述】:

我使用 Laravel valet 作为我的本地服务器,它使用我的项目文件夹名称并将它们用作本地域名。因此,如果我创建一个名为 test-website 的文件夹,我现在可以通过转到 test-website.test 在浏览器中访问它。

启动节点应用程序,我可以在浏览器中访问应用程序的唯一方法是转到 localhost::3000。很好,它可以工作,但我更喜欢自定义域名,例如新节点应用程序测试。有什么办法可以做到这一点,甚至更好,有没有什么程序可以像 Laravel Valet 那样实现自动化?

【问题讨论】:

    标签: node.js laravel valet


    【解决方案1】:

    假设您希望您的域名为node.test。您必须在~/.valet/Nginx 中创建一个名为node.conf 的文件。

    节点配置:

    map $sent_http_content_type $expires {
        "text/html"                 epoch;
        "text/html; charset=utf-8"  epoch;
        default                     off;
    }
    
    server {
        listen          80;             # the port nginx is listening on
        server_name     node.test;    # setup your domain here
    
        gzip            on;
        gzip_types      text/plain application/xml text/css application/javascript;
        gzip_min_length 1000;
    
        location / {
            expires $expires;
    
            proxy_redirect                      off;
            proxy_set_header Host               $host;
            proxy_set_header X-Real-IP          $remote_addr;
            proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto  $scheme;
            proxy_read_timeout          1m;
            proxy_connect_timeout       1m;
            proxy_pass                          http://127.0.0.1:3000; # set the adress of the Node.js instance here
        }
    }
    

    来源:Valet Github: is it possible to share node.js program running on port 3000

    【讨论】:

      【解决方案2】:

      好吧,其实我只是自己解决了..哈哈

      所以在我添加的 hosts 文件中:

      127.0.0.1:80 nodeapp.localhost
      

      转到该地址有效,并且似乎与我的 Laravel Valet 域没有冲突。

      请注意,我确实尝试使用扩展名 .test,这是我用于 Laravel Valet 网站的扩展名,但由于显而易见的原因,这不起作用。

      【讨论】:

        猜你喜欢
        • 2011-05-03
        • 1970-01-01
        • 1970-01-01
        • 2014-12-21
        • 2013-08-25
        • 1970-01-01
        • 1970-01-01
        • 2015-08-13
        • 1970-01-01
        相关资源
        最近更新 更多