WordPress.org

Ready to get started?Download WordPress

Forums

nginx - Network admin pointing to root as opposed to subdirectory (85 posts)

  1. Pothi
    Member
    Posted 1 year ago #

    hgrianevans wants to use mix on www and non-www. I generally use separate blocks but his case common block will make it easy to maintain config going ahead.

    I understand what hgrianevans wants to achieve. I just put my opinion. There is nothing wrong with your suggestion.

    IMO, it is even easier to maintain, if hgrianevans installs WordPress with 'www'. :)

  2. rahul286
    Member
    Posted 1 year ago #

    IMO, it is even easier to maintain, if hgrianevans installs WordPress with 'www'. :)

    Agree. :-)
    Life is easy when you use either WWW or non-WWW everywhere. We prefer not to use WWW (sticking with WordPress side) :-)

  3. hgrianevans
    Member
    Posted 1 year ago #

    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$ http://feeds.feedburner.com/exampleNews last;
    }
    if ($http_user_agent !~ FeedBurner) {
    rewrite ^/somearea/archives/somearea.xml$ http://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;
    }
    }
  4. hgrianevans
    Member
    Posted 1 year ago #

    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.

  5. Pothi
    Member
    Posted 1 year ago #

    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.

    That's why I joined in the conversation in this thread, even though I have been keeping an eye to this thread since its beginning. :)

    My guess was (and still is) that the issue you see is due to Nginx and there is nothing with the installation of WP or how it thinks about its URLs. Please visit http://web-sniffer.net/ and type yourdomain.com/sub-directory/wp-login.php and let us know what HTTP status code, you get. If you get 200, then both Nginx and WP are working correctly. If you get 301 or 404, then it is time to dig through the error-logs of your Nginx. Whether you use Windows or Linux server, check your access and error logs continuously (in Linux, it could be done with tail -f /path/to/nginx/access.log), when you type different URLs (such as yourdomain.com/sub-directory/wp-login.php, yourdomain.com/sub-directory/, http://www.yourdomain.com/sub-directory, etc). That should give more ideas to figure out the issue.

  6. hgrianevans
    Member
    Posted 1 year ago #

    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.

  7. Pothi
    Member
    Posted 1 year ago #

    My guess is that it could be due the incorrect Nginx configuration at the time of installation of multisite.

  8. hgrianevans
    Member
    Posted 1 year ago #

    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.

  9. Pothi
    Member
    Posted 1 year ago #

    I understand what you've been going through. Please be advised that you still need to make changes in my configuration to make it work for your use case. For example, as you may already aware of, I use fastcgi_pass fpm; that you have to modify it as fastcgi_pass 127.0.0.1:10004; to make the entire configuration to work for your particular server. Also, please just removelocation / { try_files $uri $uri/ /index.php; } line in my "globals/common-locations.conf" file and insert the following to redirect every non-WP to 'www' version of the site (aka non-WP site)...

    location / {
      return 301 $scheme://www.domainname.com$request_uri;
    }

    As you are probably using a separate server for 'www' version of the site, please remove the first server block of my configuration that does 301 redirect irrespective of what the content is based upon.

  10. rahul286
    Member
    Posted 1 year ago #

    @hgrianevans
    There are many things I see quite non-standard in your config.

    Its hard to find out problem without debugging. A quick advise would we to move if{..} block outside location{..} block... (whenever possible)
    Reason - http://agentzh.blogspot.in/2011/03/how-nginx-location-if-works.html

    If you need some help in debugging your live-site, please try - http://rtcamp.com/tutorials/debugging-nginx-configuration/

  11. hgrianevans
    Member
    Posted 1 year ago #

    @rahul286,

    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.

  12. hgrianevans
    Member
    Posted 1 year ago #

    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 http://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?

  13. Pothi
    Member
    Posted 1 year ago #

    @Pothi, yes I changed the fpm lines.

    If you already tried my configuration during the installation process of WP multisite, and if you still see the issue, then I'm unsure how to troubleshoot further. I'm sorry.

    My configuration works fine for me and I've provided you a live (example) site that is still live as of this writing. If I could not administer my live example site, I could not have created the sites or could not have changed the themes in those sites.

    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?

    I'm more into server admin, than into WordPress core. So, I don't know the answer to the above question. Sorry, again.

    I'm still curious on what went wrong for your specific situation. So, I'm not unsubscribing from this thread. But, you may not get my further replies as I do not know how to troubleshoot further. :( Please feel free to mention me, if you need my attention or assistance.

  14. hgrianevans
    Member
    Posted 1 year ago #

    @Pothi,

    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. :-(

  15. rahul286
    Member
    Posted 1 year ago #

    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.

    Just because something works doesn't make it standard.

    Your config uses a lot of if directives, rather than better and more efficient try_file

    Sections like following have unnecessary stuff!:

    location ~ /(various|extensionless|files|in|subdirs)(/|$) {
    if ($uri ~ ^(.*/(various|extensionless|files|in|subdirs))($|/.*)) {
    rewrite ^(.*/(various|extensionless|files|in|subdirs))($|/.*) $1.php?mypath=$3 last;
    }
    }

    You can write one line only (something like below) and it can do job of above 3 lines:

    rewrite ^(.*/(various|extensionless|files|in|subdirs))($|/.*) $1.php?mypath=$3 last;

    You can have rewrite like above directly in server {..} block. See - http://wiki.nginx.org/HttpRewriteModule#rewrite

    Debugging is easy when you remove unwanted lines from your config...

    And for this $base = '/';... try manually fixing it to:

    $base = '/blogs/';
    define('PATH_CURRENT_SITE', '/blogs/');
  16. hgrianevans
    Member
    Posted 1 year ago #

    I'm gonna have another go with your config on Saturday.

  17. hgrianevans
    Member
    Posted 1 year ago #

    @rahul286,

    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.

  18. hgrianevans
    Member
    Posted 1 year ago #

    Spoke a little too soon. The new site /blogs/newsite is unstyled. Will look at the debug log.

  19. hgrianevans
    Member
    Posted 1 year ago #

    @rahul286,

    I think it's a try files issue...will dig some more

  20. rahul286
    Member
    Posted 1 year ago #

    Can u run command nginx -V and paste its output here? Please note that its capital V.

    nginx -V
  21. hgrianevans
    Member
    Posted 1 year ago #

    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.

  22. rahul286
    Member
    Posted 1 year ago #

    Your nginx version is recent one so issue there.

    Must be config issue!

    If you are trying my config, then please have a look at - http://rtcamp.com/tutorials/wordpress-nginx-setup-conventions/

    You are on Centos/RHEL I guess. And all my work is on Ubuntu.

    May be above link can help you make necessary adjustments to config so that it can match your different paths on your system.

  23. hgrianevans
    Member
    Posted 1 year ago #

    @rahul286

    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 http://www.example.com?

  24. rahul286
    Member
    Posted 1 year ago #

    Following lines checks:

    location / {
                    try_files $uri $uri/ /blogs/index.php?$args ;
            }

    if requested URL is outside /blogs/ first.

    Does your application at example.com also need URL rewrite support?

  25. hgrianevans
    Member
    Posted 1 year ago #

    @rahul286,

    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 http://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: http://wordpress.org/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.

Topic Closed

This topic has been closed to new replies.

About this Topic