You are not logged in.
I have my own webserver setup and I'm using Nginx to serve PhpMyAdmin and Pydio, and I'm also using it as a reverse proxy for all of my Usenet Apps. I wanted to setup a WordPress Resume site as my main page and when I looked it up on the wiki it recommended Apache. I googled a few reasons why and even WordPress recommends Apache over Nginx, so I went ahead and set it up on Apache, everything works well, I have Apache running on port 8080. I attempted to use Nginx as a reverse proxy for WordPress and ran into a bunch of problems: the main page doesn't work at all and the Dashboard has no formatting. I noticed that WordPress has a few Nginx helper plugins and there are configs out there for Nginx, so I was wondering would it be better to use WordPress on Nginx or set it up as a reverse proxy? I'd like to ditch Apache completely since I don't really like it, it's too much for my needs.
Offline
I was able to migrate completely over to NGINX. Here's an include that I use for wordpress sites:
#
# Wordpress.org NGINX recommended configuration
#
# Adapted from http://codex.wordpress.org/Nginx
#
#
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
# Deny access to any files with a .php extension in the uploads directory
location ~* ^/wp-content/uploads/.*.php$ {
deny all;
access_log off;
log_not_found off;
}
# Deny access to any files with a .php extension in the uploads directory for multisite
location ~* /files/(.*).php$ {
deny all;
access_log off;
log_not_found off;
}
# WordPress single blog rules.
# Designed to be included in any server {} block.
# This order might seem weird - this is attempted to match last if rules below fail.
# http://wiki.nginx.org/HttpCoreModule
location / {
try_files $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# Directives to send expires headers and turn off 404 error logging.
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 24h;
log_not_found off;
}
# Uncomment one of the lines below for the appropriate caching plugin (if used).
#include global/wordpress-wp-super-cache.conf;
#include global/wordpress-w3-total-cache.conf;
# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ \.php$ {
# Zero-day exploit defense.
# http://forum.nginx.org/read.php?2,88845,page=3
# Won't work properly (404 error) if the file is not stored on this server, which is entirely possible with php-fpm/php-fcgi.
# Comment the 'try_files' line out if you set up php-fpm/php-fcgi on another machine. And then cross your fingers that you won't get hacked.
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
}
Save that as wordpress.conf, and then the nginx server stanza for a wordpress site is just:
server {
server_name www.example.com;
root /path/to/wordpress;
client_max_body_size 8M;
try_files $uri $uri/ /index.php?q=$request_uri;
include /path/to/wordpress.conf;
}
Last edited by mediaserf (2016-10-31 21:11:40)
Offline
I finally got it to work, my biggest headache actually lied in my SQL table for WordPress since I already had it setup for Apache. When I visited my site hosted by Nginx it would redirect to my Apache hosted version on port 8080, even though that redirect didn't exist anywhere in any of my Nginx configs.
I had to change siteurl and home in the wp_options table to finally fix it.
Here's the Nginx wordpress.config I used which I placed in /etc/nginx/sites-enabled/
server {
listen 80;
server_name mydomain.us;
return 301 https://\$server_name\$request_uri;
}
server {
listen 443 ssl default_server;
server_name mydomain.us;
ssl_certificate /etc/letsencrypt/live/mydomain.us/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mydomain.us/privkey.pem;
error_log /var/log/nginx/wordpress/error.log info;
root /usr/share/webapps/wordpress;
client_max_body_size 8M;
try_files $uri $uri/ /index.php?q=$request_uri;
index index.php;
location ~ \.(php|html|htm)$ {
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
}
Offline