Welcome! Log In Create A New Profile

Advanced

Cannot get Nginx to work with my WordPress

Posted by Jwan 
Cannot get Nginx to work with my WordPress
April 27, 2018 02:57PM
Hello all

A bit of background information. I have a CentOS 7 VPS. I installed the LAMP stack on it and everything was fine, all working well, but heard how Nginx is faster, so I decided to move my sites over to Nginx. I uninstall Apache and installed Nginx.

I did not imagine things would be so complex. I have followed various instructions around the web, but nothing seems to work for me. Right now, only the homepage to my website is working, everything else doesn't. Even the homepage doesn't show certain images, not sure why.

Here is my server block for the Wordpress website:

server {
listen *:80;
server_name nativeleaf.co.uk www.nativeleaf.co.uk;

expires 86400s;
add_header Pragma public;
add_header Cache-Control "max-age=86400, public, must-revalidate, proxy-revalidate";

error_page 404 /404.html;
location /404.html {
internal;
}

error_page 403 = 404;

location ~ /(\.|wp-config.php|readme.html|licence.txt) {
return 404;
}

rewrite /wp-admin$ $scheme://$host$uri/ permanent;

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

location ~* ^.+\.(css|js)$ {
rewrite ^(.+)\.(\d+)\.(css|js)$ $1.$3 last;
expires 31536000s;
access_log off;
log_not_found off;
add_header Pragma public;
add_header Cache-Control "max-age=31536000, public";
}

error_log /var/log/nginx/nativeleaf.co.uk-error.log;
access_log /var/log/nginx/nativeleaf.co.uk-access.log;

root /var/www/html/nativeleaf.co.uk;

location / {
index index.php index.html index.htm;
}

# get friendly url links working
if (!-e $request_filename)
{
rewrite ^(.+)$ /index.php?q=$1 last;
}

# pass all PHP files through php-fpm
location ~ \.php$ {

try_files $uri =404;
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/wordpress-user/techarena51.com$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}

# deny all apache .htaccess or .htpasswd files
location ~ /\.ht
{
deny all;
}

# Deny access to hidden files
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
}

I am using php-fpm for handling the php, I've read that I must do this because Nginx is different from Apache and has to delegate the PHP stuff to either fastcgi or php-fpm, correct me if I'm wrong.

Any help would be greatly appreciated.

Thank you



Edited 1 time(s). Last edit at 04/27/2018 02:59PM by Jwan.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 246
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready