Can't access WordPress on LEMP after following tutorial exactly. Tried both building LEMP manually and using 1-click LEMP app.

December 19, 2018 582 views
Getting Started LEMP WordPress Ubuntu 18.04

Keep getting 403 Forbidden error. Firewall setup as per 1-click LEMP app default:
Status: active
To Action From


22/tcp LIMIT Anywhere
443/tcp ALLOW Anywhere
80/tcp ALLOW Anywhere
Nginx HTTP ALLOW Anywhere
22/tcp (v6) LIMIT Anywhere (v6)
443/tcp (v6) ALLOW Anywhere (v6)
80/tcp (v6) ALLOW Anywhere (v6)
Nginx HTTP (v6) ALLOW Anywhere (v6)

Nginx server blocks working, can access html static sites no problem.
SSL certificates installed with Certbot, HTTP redirects to HTTPS no problem.

Ownership/permissions:
sudo chown -R www-data:www-data /var/www/mysite.com/html
sudo chmod -R 755 /var/www

tried: sudo chown -R $USER:$USER /var/www/mysite.com/html (from my sudo user)

tried: sudo find /var/www/mysite.com/html -type d -exec chmod 755 {} \;
and: sudo find /var/www/mysite.com/html -type f -exec chmod 644 {} \;

restarted Nginx after each try, no luck. I've rebuilt my Droplet several times and have been beating my head against the wall for 3 days. I followed the tutorial exactly from:
https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-lemp-on-ubuntu-18-04
but every time when I'm finished I get 403 Forbidden at https://mysite.com
I am somewhat of a newbie but I am not stupid, and I find it hard to believe that I am the only one having this problem installing WordPress from the 1-click LEMP app. I got 2 WordPress sites working on LAMP with the 1-click WordPress app, but I want to use Nginx and I must conquer this! Please help!

3 Answers

Hello.

Shall I know what's inside

sudo nano /etc/nginx/sites-available/example.com

Thanks!

After starting from scratch one more time with 1-click LEMP app and then installing WordPress, I think my problem was simply clearing my web browser cache. I'm not sure what I did wrong the first time, but thank you! I do have one question about the file you mentioned though. After several times through the process, I combined all the steps into a single template (before installing SSL certificates):

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

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;
}

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

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

location ~ /\.ht {
    deny all;
}

}
I used this to install WordPress for 3 domains, used CertBot to install certificates and had all 3 working until I logged into my terminal and it said 'system restart required' and after rebooting I cannot start Nginx. Sudo nginx -t says 'ok' and 'successful' but error log says:
[emerg] 3840#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
Any ideas?

Wow, ok, I found the problem. The 1-click LEMP app also installs Apache2, and after installing php7.2-gd and running apt upgrade Apache takes over port 80 and if you reboot your server Nginx will not start. I don't know why Apache is installed with the 1-click LEMP but it would be nice if the docs would warn you because this was painful!

Have another answer? Share your knowledge.