nuxt on local domain?
Asked Answered
B

3

5

I've setup my .hosts file to: 127.0.0.1 local.mydomain.dk

And then in my nuxt config file i've setup:

server: {
  port: 3000, // default: 3000
  host: 'local.mydomain.dk' // default: localhost
},

And last but not least, in package.json:

"dev": "nuxt --hostname local.mydomain.dk --port 3000",

However, when running npm run dev, Nuxt still starts up on localhost:3000, and not my custom domain? And if I try going to my custom domain in the browser, I get a message "Site cannot be reached"

Is there anything else to setup Nuxt for running on a local domain ?

Buck answered 7/9, 2020 at 12:10 Comment(1)
I am at the same situation. Did you find anything that helps?Incense
I
10

Had the same problem. My solution to this issue was to:

  1. Add the following in my etc/hosts file:

    127.0.0.1 local.mydomain.dk

  2. Flush DNS (different command in each OS)

  3. Add the following in nuxt.config.js:

 

server: {
    port: 80,
    host: '0.0.0.0',
}

Now if you navigate to http://local.mydomain.dk it will work.

With this approach, I noticed that the Nuxt favicon was missing (I don't know if it introduces any other [serious] problems), so I switched to:

server: {
    port: 3000,
    host: 'http://local.mydomain.dk',
}

This time you will need to navigate to http://local.mydomain.dk:3000 to work.

Incense answered 22/9, 2020 at 12:37 Comment(3)
How to revert this (trying to troubleshoot SSL by disabling custom domain)? I disabled my custom domain in hosts file, flushed OS dns, and configured Nuxt to not use my custom domain. Yet Nuxt is still building links using the custom domain!Malaguena
@MarsAndBack have you tried to clear browser's cached data?Incense
Eventually some cache must have been cleared. I reverted commits, re-built everything and in the end there was no more problem. Was really frustrating!Malaguena
D
1

First add the host name in my etc/hosts file:

127.0.0.1    local.mydomain.dk

For nuxt3 add below config in nuxt.config.ts file:

devServer: {
  port: 3000, // default: 3000
  host: 'local.mydomain.dk' // default: localhost
},
Deflation answered 8/12, 2023 at 10:54 Comment(0)
E
0

I tried to connect Telegram Oauth to nuxtjs and I wasted a lot of time trying to open a domain locally because it doesn't accept Ports. So I want to write down the method I did.

  1. Ngnix Stable version dowload and install C:\ngnix folder

enter image description here

  1. Edit C:\ngnix\conf\nginx.conf enter image description here

  2. Enter My code


worker_processes  1;

events {
    worker_connections  1024;
}

http {
map_hash_bucket_size 128;

    map $sent_http_content_type $expires {
        "text/html"                 epoch;
        "text/html; charset=utf-8"  epoch;
        default                     off;
    }   

    server {
        listen       80;
        server_name  quest.localhost;

        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://localhost:3000; # set the address of the Node.js instance here
    }

}

  1. quest.localhost here is the domain I use You can change it yourself.

enter image description here

  1. Enter cmd and run start nginx.exe in C:\ngnix. Also do nginx -s reload against every extimole since you changed the ngnix.conf file

enter image description here

Now let's enter the domain name

enter image description here

Wow it worked

Employment answered 7/9, 2022 at 15:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.