3

I'm trying to setup Nginx (1.14.2) installed from the Nginx PPA. The default page works confirmation the successful installation and working of the web server, but when I try to create my own server it doesn't work. I see many setup resources online making mention of sites-available and sites-enabled directories, but this version of nginx doesn't seem to have it. However, the version of nginx which was available on the ubuntu servers did contain these folders. Here are the contents of the /etc/nginx:

root@laravel:/etc/nginx# ls 
conf.d  fastcgi_params  koi-utf  koi-win  mime.types  modules  
nginx.conf  scgi_params  uwsgi_params  win-utf

This is my /etc/nginx/nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

This is my /etc/nginx/conf.d/test.conf

server {                                                              
    listen 80;
    server_name test.dev www.test.dev;
    root /home/homestead/web;
}

This is the message I get from the browser:

image error

  • What do you get when you run ping www.test.dev? – Bert Feb 6 at 14:56
  • 1
    Your server block listens on port 80. Your browser is trying to connect to port 443 (https). Try it without https or set it up on your nginx. – Gerald Schneider Feb 6 at 14:57
  • That domain name is owned by Google. You should use another domain name. – Michael Hampton Feb 6 at 15:16
  • @Bert Name or service not known – Rohitus Feb 6 at 15:30
  • @GeraldSchneider I tried it without https and the result is the same. – Rohitus Feb 6 at 15:31
2

The message you get 'name or service unknown' when you try to ping www.test.dev is a good indicator that there is no DNS record for that domain.

Modifying your hosts file enables you to override the domain name system (DNS) for a domain on a specific machine. DNS management is useful when you want to test your site without the test link , and for other DNS-related reasons.

Modifying your hosts file causes your local machine to look directly at the address that you specify.

In this case you want to point www.test.dev to 127.0.0.1 or localhost. You want to create an entry like the following at the bottom of the file:

127.0.0.1 www.test.dev

Open a Terminal window.

  1. Enter the following command to open the hosts file in a text editor: sudo nano /etc/hosts
  2. Enter your user password
  3. Make the necessary changes to the file
  4. Press Control-X
  5. When you are asked if you want to save your changes, enter 'y'

At this point, your browser should load the page successfully.

  • It Works! I can't seem to mark this as the accepted answer. But thanks much. That's exactly what I needed! – Rohitus Feb 6 at 16:58
  • 1
    The original question was posted by Abdulluh Mckenzie but comments and edits are from @Rohitus. As Rohitus is not the OP, they cannot mark answer as correct/accepted. Are Abdulluh Mckenzie and Rohitus same person? If so, accounts should be merged – Dave M Feb 7 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.