I’m trying to get WordPress up and working on my personal dedicated server, and I’m having some trouble with NGINX.
I used this installation script GitHub - arakasi72/rtinst: seedbox installation script for Ubuntu and Debian systems in order to install everything I needed / wanted for hosting ruTorrent, and it works swimmingly.
I had no trouble buying a domain name from Namecheap. I had no trouble buying, configuring, and installing an SSL certificate from Comodo. When I type my-domain-name.tld
into any web browser, everything works. It shows me the NGINX landing page. I have a nice padlock icon by my domain name.
I figured, okay… let me install WordPress next, because I’d like to make a gallery for my art and perhaps some day even sell it, and as I understand, extending WordPress with a webshop plug-in is fairly easy.
I’ve read enough to know that there’s a lot of hate for WordPress around here (and after reading a huge thread with Wendell’s explanations, it sounds like reasonable hate), however whether I decide to use WordPress, or Hugo, or whatever CMS, I think I still need to figure out / understand this issue I’m having with NGINX.
EDIT: My dedicated server is an Ubuntu 20.04.5 LTS installation. That probably shouldn’t matter, but I thought I’d mention it.
So right now, in my /etc/nginx/sites-available/
directory, I have a file called “default
”.
It looks like this:
server {
listen 80;
listen [::]:80;
server_name my-domain-name.tld www.my-domain-name.tld;
root /var/www;
index index.html index.php index.htm;
error_page 403 = @denied;
#Below enter IP address or block to allow, eg LAN and/or VPN blocks
allow 10.0.0.0/8;
allow 172.16.0.0/12;
allow 192.168.0.0/16;
deny all;
location @denied {
return 301 https://$host$request_uri;
}
location / {
try_files $uri $uri/ =404;
}
location /rutorrent {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
include /etc/nginx/conf.d/php;
include /etc/nginx/conf.d/cache;
}
#include /etc/nginx/sites-available/dload-loc;
location ~ /\.ht {
deny all;
}
}
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name my-domain-name.tld www.my-domain-name.tld;
root /var/www;
index index.html index.php index.htm;
client_max_body_size 40m;
ssl_certificate /etc/ssl/www_my_domain_name_tld_chain.crt;
ssl_certificate_key /etc/ssl/private/www_my_domain_name_tld.key;
ssl_session_timeout 5m;
location / {
try_files $uri $uri/ =404;
}
location /rutorrent {
client_max_body_size 40m;
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
include /etc/nginx/conf.d/php;
include /etc/nginx/conf.d/cache;
}
#include /etc/nginx/sites-available/dload-loc;
include /etc/nginx/sites-available/webmin-loc;
location ~ /\.ht {
deny all;
}
}
I decided to follow what I thought would be a simple tutorial for this: Install WordPress on Ubuntu 20.04 with Nginx, MariaDB, PHP7.4 (LEMP)
Everything was smooth sailing. Right up until Step 4.
Step 4 says make a .conf file at /etc/nginx/conf.d/example.com.conf
. Okay. No problem. I did sudo nano /etc/nginx/conf.d/my-domain-name.tld.conf
and then pasted this in:
server {
listen 80;
listen [::]:80;
server_name www.example.com example.com;
root /usr/share/nginx/example.com/;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ /index.php;
}
location ~ ^/wp-json/ {
rewrite ^/wp-json/(.*?)$ /?rest_route=/$1 last;
}
location ~* /wp-sitemap.*\.xml {
try_files $uri $uri/ /index.php$is_args$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
client_max_body_size 20M;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include snippets/fastcgi-php.conf;
# Add headers to serve security related headers
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Permitted-Cross-Domain-Policies none;
add_header X-Frame-Options "SAMEORIGIN";
}
#enable gzip compression
gzip on;
gzip_vary on;
gzip_min_length 1000;
gzip_comp_level 5;
gzip_types application/json text/css application/x-javascript application/javascript image/svg+xml;
gzip_proxied any;
# A long browser cache lifetime can speed up repeat visits to your page
location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
access_log off;
log_not_found off;
expires 360d;
}
# disable access to hidden files
location ~ /\.ht {
access_log off;
log_not_found off;
deny all;
}
}
Once I saved the .conf file, that’s when all Hell broke loose.
sudo nginx -t
returned errors along the lines of:
nginx: [warn] conflicting server name "www.<domain_name.tld>" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "<domain_name.tld>" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "www.<domain_name.tld>" on [::]:80, ignored
nginx: [warn] conflicting server name "<domain_name.tld>" on [::]:80, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Okay, so I was able to figure out on my own that apparently NGINX sees this as configuration files for two separate servers and not for a single web server running two services - WordPress and ruTorrent.
Quick note: I changed the location of the wordpress directory from /usr/share/nginx/example.com
in the /etc/nginx/conf.d/my-domain-name.tld.conf/
to /var/www/my-domain-name.tld.conf
. I did change the appropriate lines in the .conf file above as well, of course.
I did remember to do the things I need to do, like sudo chown www-data:www-data /var/www/my-domain-name.tld/ -R
My questions are the following:
-
Which file do I edit to actually make NGINX serve up WordPress such that when a user types in
www.my-domain-name.tld
in their web browser and presses the Enter key, they’ll be graced with my WordPress installation (after I myself can actually access it and go through the installation process)? -
What do I actually type, and in which file do I actually type it? Clearly I’m doing something wrong, and I’ve tried a lot of “workarounds”.
I tried putting parts of the .conf file from the LinuxBabe tutorial in the default
file in /etc/nginx/sites-available/
. That actually did work, eventually… I think I added a bunch of the fastcgi/php related crap from the LinuxBabe file and changed the root in the default
file to var/www/wordpress
. And when I typed www.my-domain-name.tld
into the web browser, I was in fact greeted with the WordPress install page… however this broke ruTorrent. Which isn’t going to work.
So I need some real help understanding these NGINX conf files, I probably need help understanding the location
directive, because I’m pretty sure I don’t get it, either.
Finally, if you read all this… God, Allah, Buddha, whatever you believe in, bless you. If you read all this and actually want to help, a thousand blessings upon you.