JackZ
By:
JackZ

Ghost Configuration Need www

July 25, 2017 392 views
Ghost Nginx Node.js Ubuntu 16.04

OK, I am having an issue with the preconfigured Ghost image. What I want to do is use www with domain instead of naked. For example, I want http://www.example.com instead http://example.com

I first changed the /etc/nginx/sites-available/ghost file to server_name example.com and changed the /var/www/ghost/config.js file in Production to: url: 'http://www.example.com, I then attempted to access the site. When using example.com, I visit the site, but when I use www.example.com, I get the Nginix Welcome screen.

I then attempted to change he /etc/nginx/sites-available/ghost file to server_name www.example.com and got a bad gateway error 502 on example.com and a 404 error on www.example.com

I know this is a configuration error some place and I could spend hours playing around with it, but I'd prefer to ask here because I have a feeling it is a very easy to fix error.

Thanks!

2 Answers

I fixed this issue. It was a bear and took several hours to accomplish it so I am going to put it here so others Googling this issue can do what I finally did to solve it. This is a lot harder than it should be! I suspect most of the issue stem from the tutorials being ancient. While this took a lot of time to figure out, but with these commands this can take literally a few minutes.

The very first thing I had to do was move /var/www/ghost to /var/www/example.com/ghost

I also had to run service ghost stop

then I edited the System startup files by nano /etc/systemd/system/ghost.service

I edited out the location /var/www/ghost to /var/www/example.com/ghost

Now I edited configurations, you can see them below. After editing all of those, I rebooted the machine with shutdown -r now

I hope this can help someone else in the same predicament.

Here is my Config.js file with the pertinent parts---notice the port is different:
config = {
// ### Production
// When running Ghost in the wild, use the production environment.
// Configure your URL and mail settings here
production: {
url: 'http://www.example.com',
mail: {},
database: {
.......
.......
server: {
host: '127.0.0.1',
port: '2778'
}

Here is my Nginx site configuration(notice there are two server blocks and the port in location has been changed.
server {
listen 80;
listen [::]:80;

server_name www.example.com; # Replace with your domain

root /usr/share/nginx/html;
index index.html index.htm;

client_max_body_size 10G;

location / {
    proxy_pass http://localhost:2778;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_buffering off;
}

}
server {
listen 80;
servername example.com;
return 301 http://www.example.com$request
uri;
}

  • I suspect that there is some configuration somewhere that sends default requests directly to the Ghost app on Port 2368, but I can't figure out what it is or where it is. This works around the issue.

@JackZ

Add all domains to your server_name directive like this:

server_name example.com www.example.com

Hope this helps.

  • I have tried this and the same issue. It accesses the NGinx page on www.example.com and the Ghost blog on example.com

    • Please post your configuration files so we can look at them also post the last few lines of the error log when you got the 502 errors

      tail -20 /var/log/nginx/error.log.

Have another answer? Share your knowledge.