Welcome! Log In Create A New Profile

Advanced

Wordpress in subdirectory

Posted by gbark1204 
Wordpress in subdirectory
August 18, 2017 09:18AM
wordpress and nginx both have instructions on how to configure nginx to work with wordpress.

https://codex.wordpress.org/Nginx
and
https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/

both assume a server dedicated to the wordpress site.

My situation is one that has the main symfony site at https://www.mydomain.com and I want the wordpress blog to be at https://www.mydomain.com/blog/

The server is configured for mydomain.com. I have a location for a forum package at /boards/ that works fine. However, I had extreme difficulties even getting /blog/ to load a standard index file.

One piece of the wordpress codex or nginx recipe that I haven't been able to figure out how to use is the upstream php block to abstract backend connections. Is that critical?
Is there a way for me to still use the upstream php with just one location?

I've attached my nginx config. Please let me know if I can provide more information, and thank you in advance for any help you can give me!

I cannot provide a link to what is happening with this config, but I can tell you that the wordpress index file is being hit. Unfortunately it's being downloaded instead of run though in Chrome.



Edited 2 time(s). Last edit at 08/18/2017 09:26AM by gbark1204.
Attachments:
open | download - nginxconfig (4 KB)
Re: Wordpress in subdirectory
October 21, 2017 09:18PM
I have this same issue. Have you resolved it? I really want to migrate my site from Apache to nginx but this issue is in the way. Does anyone know a more active forum I can go to for these issues?
Attachments:
open | download - nginx.conf (2 KB)
Re: Wordpress in subdirectory
October 21, 2017 09:46PM
I did actually. It came down to my novice understanding of nginx location roots. I’m replying from my phone right now. I’ll post some specifics tomorrow or Monday to hopefully help you out.
Re: Wordpress in subdirectory
October 21, 2017 10:11PM
Ah, glad to hear that, thank you so much. I am pretty new to nginx and web servers myself. So far though nginx has been easier to set up in general than Apache :)
Re: Wordpress in subdirectory
October 25, 2017 11:42AM
Sorry again for the delay. Putting out proverbial fires the past 2 days.

Some background: my site is built on Symfony PHP Framework. I needed to add a blog to /blog/ and decided to go ahead and use wordpress for that piece so that my client can have full creative control there. I had two git repositories for source control and a build process to move from dev to qa to production environments. Almost all of my headaches around making this work can be traced to 1 concept: the location is based off of my main server: www.mysitesdomain.com --- so ~ /blog/ means www.mysitesdomain.com/blog/, AAAANND the location is also used for your location's root. So if your location's root is /var/www/mysite, it's going to look in /blog/ there. If you're wordpress installation is in /var/www/mysite/wordpress, then you need a /blog/ directory in there. I really hope you're having the same kind of issue. Here is my nginx config for just the wordpress piece. Maybe a real nginx expert will see all this and educate us both haha ;)

location ~ /blog/.*\.php(/|$) {
root <the full path to your wordpress installation, one directory up, with no trailing slash. ie: /var/www/mysite/wordpress is what you want here, and wordpress is /var/www/mysite/wordpress/blog/index.php>;
fastcgi_pass 127.0.0.1:9000; #### This is the local host and the port that the php-fpm service is running on
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}

# this is right out of the wordpress codex for static resources
location ~ /blog/.*\.(css|js|jpg|png|gif)$ {
root <the full path to your wordpress installation with no trailing slash. ie: /var/www/mysite/wordpress>;
}

# needed this for admin to work right
location /blog/wp-admin {
root<the full path to your wordpress installation with no trailing slash. ie: /var/www/mysite/wordpress>;
index index.php index.html;
if (!-f $request_filename) {
rewrite ^/blog/wp-admin$ /blog/wp-admin/ last;
}
}

# setting the index here didn't do it for me, so I did try_files and that worked like a charm.
location /blog/ {
root <the full path to your wordpress installation with no trailing slash. ie: /var/www/mysite/wordpress>;
try_files /blog/index.php$is_args$args /index.html;
fastcgi_pass 127.0.0.1:9000; #### This is the local host and the port that the php-fpm service is running on
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
Re: Wordpress in subdirectory
October 28, 2017 05:48PM
Sorry for the late reply. Thanks so much for your response I will try applying this config tonight hopefully and let you know how it plays out.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 164
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