Help deploying with Nginx

Hey all,

I’ve got a basic website set up and am able to run my site on localhost:1313

But every Nginx config I have scrounged for on the net for doesn’t seem to work with my particular setup

I’m hoping to use Nginx on a Linode VPS running on Debian 9

Here’s my directory structure using the hikari theme:

$ pwd
/home/roman/blog
$ ls -al
total 40
drwxr-xr-x 9 roman roman 4096 Jun 26 04:16 .
drwxr-xr-x 9 roman roman 4096 Jun 26 04:07 ..
drwxr-xr-x 2 roman roman 4096 Jun 26 03:05 archetypes
-rw-r--r-- 1 roman roman 1281 Jun 26 03:05 config.toml
drwxr-xr-x 3 roman roman 4096 Jun 26 03:05 content
drwxr-xr-x 2 roman roman 4096 Jun 26 03:05 data
drwxr-xr-x 8 roman roman 4096 Jun 26 03:05 .git
drwxr-xr-x 2 roman roman 4096 Jun 26 03:05 layouts
drwxr-xr-x 3 roman roman 4096 Jun 26 03:05 static
drwxr-xr-x 3 roman roman 4096 Jun 26 03:05 themes

/etc/nginx/nginx.conf

user roman;

events {
}

http {
    server {
	listen 80;
   	server_name http://www.romanscollins.net www.romanscollins.net *.romanscollins.net; 
	location / {
	    root /home/roman/blog/;
	}
    }
}

I get 403 Forbidden when I go to my domain in my web browser, also, should I be using /etc/nginx/nginx.conf?

I do not plan on hosting any other sites on this server.

System info:

$ hugo env
Hugo Static Site Generator v0.18.1 BuildDate: 2016-12-30T16:01:10Z
GOOS="linux"
GOARCH="amd64"
GOVERSION="go1.7.4"

$ nginx -v
nginx version: nginx/1.10.3
$ uname -r 
4.9.0-6-amd64
$ screenfetch 
         _,met$$$$$gg.           roman@localhost
      ,g$$$$$$$$$$$$$$$P.        OS: Debian 9.4 stretch
    ,g$$P""       """Y$$.".      Kernel: x86_64 Linux 4.9.0-6-amd64
   ,$$P'              `$$$.      Uptime: 56m
  ',$$P       ,ggs.     `$$b:    Packages: 500
  `d$$'     ,$P"'   .    $$$     Shell: fish
   $$P      d$'     ,    $$P     CPU: 2x Intel Xeon CPU E5-2680 v3 @ 2.5GHz
   $$:      $$.   -    ,d$$'     RAM: 66MiB / 3955MiB
   $$\;      Y$b._   _,d$P'     
   Y$$.    `.`"Y$$$$P"'         
   `$$b      "-.__              
    `Y$$                        
     `Y$$.                      
       `$$b.                    
         `Y$$b.                 
            `"Y$b._             
                `""""           
                          

This isn’t the right place for nginx help but, it looks like you’re trying to serve the project folder.

You need to run hugo and have it generate the files to your hosted folder. When you run hugo server it just generates to memory by default, not to disk (although a switch will let you serve from disk).

Like:

hugo --config="/home/roman/blog/config.toml" -s /home/roman/blog/ -d /home/roman/blog-public

… then serve blog-public for instance with whatever you need in nginx to do that.

Thanks, I’ll have to keep reading the nginx docs and see how I can solve the 403 Forbidden errors. This definitely helps, as I couldn’t figure out how to build the site for serving in the first place

TIA for any extra help

Understandable if no one wants to help me with Nginx here

403 errors are permissions usually in my experience.

Edit: or, this could simply be because there’s nothing in that folder for nginx to serve. Create the site folder, point nginx at it, then see if you get the 404. You might use chmod and/or chown in your prep script, to make sure the files are set up how nginx expects.

Wanted to add that when I am learning new server software, I go for the simplest use case. Because Hugo just generates html files, I’d get nginx serving a basic HTML file. So look for tutorials about basic config to get started.

Also, don’t serve your site from /home/. Host it from /srv/ or /var/www/ or similar. Serving it from your home directory will throw those permission errors Rick mentioned (the 403 error).

Good luck! :slight_smile:

Side note, @RomanSC, is there any reason why you’re using such old versions of Hugo, Golang, and nginx? I don’t know that this issue would be related to the old software, but I’d want to eliminate all possibilities related to old bugs that have since been fixed.

In particular, you’re using a “Legacy Version” of nginx that was released a year and a half ago. Nginx has Legacy, Stable, and Mainline releases. I’m not sure why anyone would use Legacy at this point.

There have been a massive numbers of releases and bug fixes in both Golang and Hugo since 1.7.4 and 0.18.1. If I were you, I’d update to the current releases of everything, then isolate the bug from there.

Thanks for the helpful suggestions, all.

I rebuilt the server with Arch Linux, no more old versions of hugo and nginx. I was installing hugo and nginx from the default repositories on Debian which is why the versions would be “old.” I also moved the built site from the home directory to /var/www/public and made sure the folder permissions are 755

Building the site now with:

sudo hugo --verbose --config="/home/roman/blog/config.toml" -s /home/roman/blog/ -d /var/www/public/hugo -l /home/roman/blog/layouts -t . 

For some reason I have to use -t . to specify the theme otherwise hugo will look for:

Error: Unable to find theme Directory: /home/roman/blog/themes/home/roman/blog/themes                                                                                                                                                                                          

The site is now being served but there’s something wrong with the theme:
http://romanscollins.net/

I suspect it could still be nginx since the site runs fine locally with hugo serve?

The theme is supposed to be hikari:
https://themes.gohugo.io/theme/hikari/

Anyhow, that’s where I’m at :smiley:

Thanks all

Just a side not with my security hat on here.

For goodness sake (and for everyone’s sake), make sure you are staying current with software that is exposed to the Internet unless you want your machines leaking data and participating in botnets.

Most of the processes for finding and executing vulnerabilities in Internet-facing servers are entirely automatic and there are thousands - quite possibly millions - of bots searching for vulnerabilities 24x7.

I installed some security features. But that’s completely off-topic. Everything is going to be updated pretty frequently.

My priority is figuring out why my site looks like this:

I don’t know if it’s an issue with nginx or hugo.

For the nginx user I’m using http, the default on arch /var/www/public is owned by http, and my built hugo lives at /var/www/hugo

Here’s my /etc/nginx/nginx.conf:

user http;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        listen       [::]:80;
        #server_name  localhost;
	server_name wwww.romanscollins.net;

        #charset koi8-r;
	charset utf-8;

        #access_log  logs/host.access.log  main;

        location / {
            root   /var/www/public/hugo;
            index  index.xml sitemap.xml;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        # error_page   500 502 503 504  /50x.html;
        # location = /50x.html {
        #     root   /usr/share/nginx/html;
        # }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

Here’s the source to my site:

I’m unsure why the theme is not rendering, it runs fine with hugo serve locally

Probably that line. From your screenshot, it looks like you are loading the site feed, which makes sense as you tell nginx to serve that as the index: index.xml

Edit: it should be index.html.

1 Like

3 posts were split to a new topic: Empty theme directory when using build parameters