Installed ghost on nginx in subfolder and I got 403 error

Hi dear people, I am literally pulling my hair couple of days trying to solve the issue I have, I will explain in detail as much as possible:

  • I have new vps ubuntu 18.04, I installed nginx, installed ssl, installed mysql, installed ufw firewall all went good.
  • installed WordPress in the root, so when you go to http://mysite.com WordPress runs, no issues.
  • I run nginx -t no errors.
  • I installed node, created new database, created new user and switched to that user, created new directory /myghost in /var/www/mysite.com/html so to be /var/www/mysite.com/html/myghost and in there I installed ghost via the ghost-cli.
  • Followed the official guide how to install with ghost-cli.
  • All went smooth no issue, ghost started, ran ghost doctor and no errors.

This is my default conf in /etc/nginx/sites-enabled:

        server {
                listen 80 default_server;
                listen [::]:80 default_server ipv6only=on;

                root /var/www/mysite.com/html;
                index index.php index.html index.htm;

                server_name mysite.com www.mysite.com;
                # remove HTTP and forward to HTTPS
                rewrite ^/(.*) https://mysite.com/$1 permanent;

        }

        server {
        	# SSL configuration
        	 listen 443 ssl default_server;
        	 listen [::]:443 ssl default_server;
                        
        	ssl_certificate /etc/ssl/certs/mysite.com_chained.crt;
        	ssl_certificate_key /etc/ssl/private/mysite.com.key;

        	ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        	ssl_prefer_server_ciphers on;
        	ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';         

        	root /var/www/mysite.com/html;

        	# Add index.php to the list if you are using PHP
        	index index.html index.php index.htm index.nginx-debian.html;

        	server_name _;

        	location / {
        		# First attempt to serve request as file, then
        		# as directory, then fall back to displaying a 404.
                try_files $uri /index.html index.php;
        	}
        	
        	location ^~ /myghost/ {
        		autoindex on;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_set_header X-NginX-Proxy true;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_pass https://127.0.0.1:2369;
                proxy_redirect off;
            }

        	# pass PHP scripts to FastCGI server
        	#
                #CONSIDER ADDING MORE HERE IF LARAVEL?
        	#location ~ \.php$ {
        	#	include snippets/fastcgi-php.conf;
        	#
        	#	# With php-fpm (or other unix sockets):
        	#	fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        	#	# With php-cgi (or other tcp sockets):
        	#	fastcgi_pass 127.0.0.1:9000;
        	#}

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

And this is for server stated in my config.production.json file in my /myghost folder:

"url": "https://mysite/myghost/",
  "server": {
    "port": 2369,
    "host": "127.0.0.1"
  },

as you can see the ports and host match in both files.

My issue is that when I navigate to http://mysite.com/myghost I see 403 Forbidden, however weird too is that when I go to http://mysite.com/myghost/ghost I see there a 404 not found error?

  • Now when I check the error.log file I get only this messages:
    *[error] 30939#30939: 1 directory index of “/var/www/mysite.com/html/myghost/” is forbidden, client: 92$
  • I checked the permissions for the /myghost golder and they are 775.

Please can you tell me what could be? I am puzzled, I tried changing many things, lots of trials and errors, would really appreciate your input and experience to help me. Thank you very much!

Hey everyone, me again, I see no replies here and I tried many other suggestions from around the internet, but nothing worked out for me, however, I decided to put the installation in a subdomain instead in a subfolder, all went well this time, I wrote a blog post about this, so if anyone else in future stumbles upon same issue can take a read and follow the following guide that I wrote from my experience here: Install Ghost blog on a subdomain using Nginx server on Ubuntu 18.04 | by Ivo Culic | Medium

Hope this helps.

Hello, I tried the same thing. Install ghost in subdir … I fixed with this rule in the server block … https://www.ghostforbeginners.com/how-to-install-ghost-in-a-subdirectory/

Work for me