hgrianevans
Forum Replies Created
-
I’m sorry, I might not have been clear, but I was referring to the situation a few posts ago where my non-WP site directories, etc are running in a https://www.example.com server block and the wordpress blogs are running in an example.com to deal with WP’s preference to drop the www.
So as I mentioned before if someone types in an url that’s like example.com/some/url/that/is/not/wp I’d love it if they could be redirected to www.example.com/some/url/that/is/not/wp
Right now, for example, if someone chops of the /blogs/testblog and tries to go to example.com, the config above tosses a 403 error in nginx.
Does your application at example.com also need URL rewrite support?
Yes, I listed a bunch of rewrites in the reply here: https://www.ads-software.com/support/topic/nginx-network-admin-pointing-to-root-as-opposed-to-subdirectory/page/3?replies=84#post-3202075
p.s. love the tutorials on your site. started reading through them.
I think it’s finally working.
To sum it up:
in wp-config.php I changed
$base = '/blogs'; define('PATH_CURRENT_SITE', '/blogs/');
I changed the path in wp-site and wp-blogs to /blogs/
This was my server config for the example.com server:
map $uri $blogname{ ~^(?P<blogpath>/[_0-9a-zA-Z-]+/)files/(.*) $blogpath ; } map $blogname $blogid{ default ""; /testblog/ 2; #/site2/ 3; } server { server_name example.com ; access_log /usr/local/nginx/logs/access.log; error_log /usr/local/nginx/logs/testwp.log debug; root /usr/local/nginx/htdocs ; index index.php; if ($request_uri ~* "^/blogs(/[_0-9a-zA-Z-]+)?/files/(.*)"){ set $rtfile $2; } location ~ ^/blogs(/[_0-9a-zA-Z-]+)?/files/(.*)$ { try_files /wp-content/blogs.dir/$blogid/files/$rtfile /wp-includes/ms-files.php?file=$rtfile ; access_log off; log_not_found off; expires max; } #avoid php readfile() location ^~ /blogs.dir { internal; alias /usr/local/nginx/htdocs/blogs/wp-content/blogs.dir ; access_log off; log_not_found off; expires max; } if (!-e $request_filename) { # wp-admin to wp-admin/ rewrite /wp-admin$ $scheme://$host$uri/ permanent; #other wp-* files/folders rewrite ^/blogs(/[_0-9a-zA-Z-]+)?(/wp-.*) /blogs$2 last; #other php files rewrite ^/blogs(/[_0-9a-zA-Z-]+)?(/.*\.php)$ /blogs$2 last; } location / { try_files $uri $uri/ /blogs/index.php?$args ; } location ~ \.php$ { try_files $uri /blogs/index.php; include /usr/local/nginx/conf/fastcgi-php.conf; fastcgi_pass 127.0.0.1:10004; } location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ { access_log off; log_not_found off; expires max; } location = /favicon.php { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } location ~ /\. { deny all; access_log off; log_not_found off; } }
Many thanks to you Mika and Pothi.
With the above config (and having seen my other config) do you have any suggestions now for redirecting non-/blogs URLs back to https://www.example.com?
nginx version: nginx/1.2.2
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-52)
TLS SNI support disabled
configure arguments: –with-http_stub_status_module –with-http_ssl_module –with-debug –with-http_gzip_static_module –with-cc-opt=’-I /usr/include’ –with-ld-opt=’-L /usr/lib’This is the type of afternoon I’m having. Now the WP screens have gone blank…nothing’s being served.
I think it’s a try files issue…will dig some more
Spoke a little too soon. The new site /blogs/newsite is unstyled. Will look at the debug log.
Changing the wp-config to :
$base = ‘/blogs/’;
define(‘PATH_CURRENT_SITE’, ‘/blogs/’);just results in an “Error establishing database connection” message.
I manually changed the path entries in wp-blogs and wp-site to /blogs/ and that appears to have worked. So far, so good.
I’m gonna have another go with your config on Saturday.
Thanks for your all your help.
I just nuked the WordPress database and directory and the only thing in the domain.com server block was your config.
Again, WP installed fine in /blogs. Again, I was able to go to WP in /blogs. Did the network install and, sadly, once again this is what WP gave:
define('MULTISITE', true); define('SUBDOMAIN_INSTALL', false); $base = '/'; define('DOMAIN_CURRENT_SITE', 'domain.com'); define('PATH_CURRENT_SITE', '/'); define('SITE_ID_CURRENT_SITE', 1); define('BLOG_ID_CURRENT_SITE', 1);
This is nuts. I’m going to try hard-coding the abspath value. If that fails, I just might do multiple installs. ??
Just one other quick note: last night when I tried a clean install with Rahul286’s config, the only thing in the domain.com server block was Rahul’s config, nothing else. It never touched the https://www.domain server block at all.
Which WP file handles the network/multisite end of the install process? Maybe we could see where WP is grabbing the variable from that’s messing up /blogs to / in the database?
There are many things I see quite non-standard in your config.
Well, anything that looks non-standard has been the result of lengthy forum threads involving Nginx’s author Igor, so if he’s cool with it, I’m cool with it. ?? The stuff’s been working for years.
@pothi, yes I changed the fpm lines. As I’ve said to both of you, serving the WordPress is no problem. It’s that wordpress is putting / in some of it’s menus and databases instead of /blogs.
Well I used rahul286’s config…which works for him… and reinstalled WP from scratch. Same problem.
It’s 639am so I’m heading off to bed finally (very tired). I’ll nuke the WP database and files tomorrow and try your config.
There’s no problem with domain.com/blogs/wp-login.php It returns a 200.
What I’m talking about is that the menu item My Sites>Network Admin>(Dashboard|Sites|Users|Visit Networks) is pointing to /wp-admin, etc instead of /blogs/wp-admin and the wp-site table is point to / instead of /blogs
That’s the main problem I’m facing. Nginx isn’t creating the URL’s that WP is displaying in its menus and Nginx isn’t putting the wrong directory in wp-sites. Why is the wrong info being inserted into WP’s database?
In other words I’m able to serve the site up, I just can’t administer it.
Pothi and Rahul286,
Skipping the www vs. non-www debate for a second…and yes I’m researching right now how Google deals with the change…do either of you have any inkling as to my big question of why WP keeps thinking some of it’s URLs are in root when it’s installed in a subdirectory? That’s the thing that had Mika and I banging our heads.
Took a few minutes to depersonalize the server block but here’s the config of my non-wp site:
server { listen 80; root /usr/local/nginx/htdocs; server_name www.example.com; include /usr/local/nginx/conf/fastcgi-php.conf; #shtml files are actually php files index index.shtml index.php index.html; fastcgi_intercept_errors on; error_page 404 /dhe404.shtml; error_page 403 /dhe403.shtml; charset ISO-8859-1; #gzip stuff deleted if (-f $document_root/maintenance.html) { return 503; } error_page 503 @503; location @503 { rewrite ^(.*)$ /maintenance.html break; } location / { index index.shtml index.php; } location ~ \.(shtml|php|inc)$ { fastcgi_pass 127.0.0.1:10004; } # start of extensionless stuff location ~ ^/(various|extensionless|files)(/.*$|$) { rewrite ^/(various|extensionless|files)(/.*$|$) /$1.php?mypath=$2 last; } location ~ ^/(news|somearea)(/.*$|$) { if ($http_user_agent !~ FeedBurner) { rewrite ^/news/main/main.xml$ https://feeds.feedburner.com/exampleNews last; } if ($http_user_agent !~ FeedBurner) { rewrite ^/somearea/archives/somearea.xml$ https://feeds.feedburner.com/examplessomearea last; } rewrite ^/(news|somearea)(/.*$|$) /$1.php?mypath=$2 last; } location ~ /(various|extensionless|files|in|subdirs)(/|$) { if ($uri ~ ^(.*/(various|extensionless|files|in|subdirs))($|/.*)) { rewrite ^(.*/(various|extensionless|files|in|subdirs))($|/.*) $1.php?mypath=$3 last; } } #start of new galleries check location ~ ^/galleries(/.*$|$) { if (-f /usr/local/nginx/htdocs/pixcache$request_uri/index.html) { expires 2h; rewrite ^(.*)$ /pixcache$1/index.html last; break; } rewrite ^/galleries(/.*$|$) /galleries.php?mypath=$1 last; } #end of new galleries check # end of extensionless stuff location ~* ^.+\.(jpg|jpeg|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mov)$ { error_page 403 /dhe403.shtml; expires 30d; valid_referers none blocked *.example.com example.com ; if ($invalid_referer) { return 403; } } location ~* ^.+\.html$ { expires 2h; } location ~* ^.+\.(gif|js)$ { expires 30d; } }
Pothi,
Kettle’s on…brain’s getting ready. ??
Just curious, why do you need a try_files in the non-WP section? Isn’t the try files stuff just for WP? Or is it beneficial for the non-WP stuff as well?