Report this

What is the reason for this report?

NGINX config for Wordpress in sub-directory, served on root - Ubuntu 18.04

Posted on January 1, 2019

I’ve messed around with these settings for a solid 2 hours now, but just can’t seem to get it right. I want my site to display at gemfruit.com, and the wordpress directory is at /var/www/gemfruit.com/html/wordpress. I was able to install Wordpress correctly, and later the settings under general to tell Wordpress where the directory / site are, but something about my server block is wrong.

gemfruit.com (403) gemfruit.com/wordpress (works, but should be at gemfruit.com) gemfruit.com/wordpress/wp-admin/ (works - though in my attempts, there was a point where this would not work without being followed by index.php) gemfruit.com/?p=1 (403)

I followed quite a few guides to get set up (also have cert bot for SSL), but ultimately these two:

https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-ubuntu-18-04

https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-lemp-on-ubuntu-18-04

The only place I ventured off guide, was to give Wordpress its own directory. I’ve tried to make proper sense of the server block rules, but despite my best attempts, I’m still missing something.

Lastly - what’s the difference between /index.php$is_args$args; and /index.php?$args; ? The 18.04 guide uses the former markup, where as the older 16.04 uses the latter.

server {
        root /var/www/gemfruit.com/html;
        index index.php index.html index.htm index.nginx-debian.html;
        server_name gemfruit.com www.gemfruit.com;

        location / {
                #try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.php?$args;
        }

        #location /wordpress {
        #       index index.php index.html index.htm;
        #       try_files $uri $uri/ /index.php?$args;
        #}

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }

        location = /favicon.ico { log_not_found off; access_log off; }
        location = /robots.txt { log_not_found off; access_log off; allow all; }
        location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
                expires max;
                log_not_found off;
        }

}



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello,

If your Wordpress installation is at /var/www/gemfruit.com/html/wordpress then you need to make sure that your Nginx document root is also set to /var/www/gemfruit.com/html/wordpress.

Another thing that you need to keep in mind is that your Wordpress Site and Home URLs need to be set to yourdomain.com rather than yourdomain.com/wordpress.

Regards, Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.