Porter
By:
Porter

wp-Admin Goes To 404 - wp-admin.index Does Not

September 11, 2014 5.5k views

Hey everyone,

I'm new to Digital Ocean / VPS, and just moved from shared hosting. I've got a pretty decent handle over everything the last few days, but I have an odd issue I can't solve now. I'm currently running a LEMP stack.

For whatever reason, my site.com/wordpress/wp-admin page always brings up a 404, which with my current setup redirects to site.com/oops. No other url has an issue, and I can even go to site.com/wordpress/wp-admin.index, but without the .index, it doesn't work. The login by default doesn't add index, so whenever I try to log in I get a 404.

My only guess as to what's going on, is that I messed something up when putting Wordpress in its own directory. My setup is currently in var/www/site/public_html/wordpress/, and it's on it's own server block. On Shared hosting / apache, I simply had to add a bit of code to the .htaccess file, but I read with nginx I had to edit my server block within the sites-available directory. I then copied the index.php file from wordpress to the root, and added the header bit (as I've always done for this setup). Here's what I found / added, is this correct?

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/anightinburlington.com/public_html;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name anightinburlington.com www.anightinburlington.com;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        # try_files $uri $uri/ =404;
        try_files $uri /wordpress$uri/ /wordpress/index.php?q=$uri&$args;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
    }

1 Answer

If you're want to serve WordPress from a subfolder, you'll want change your Nginx configuration from:

    location / {
        try_files $uri /wordpress$uri/ /wordpress/index.php?q=$uri&$args;
    }

to:

location /wordpress/ {
    index index.php;
    try_files $uri $uri/ /wordpress/index.php?q=$uri&$args;
}

Let us know how it goes!

  • That worked perfectly, many thanks! I'm not sure where I pulled my original code from, but I must have left something out pertaining to their setup.

    One quick question, I looked up some info here - http://wiki.nginx.org/WordPress and saw similar code, with an addition to the fastcgi bit:

     location ~ \.php$ {
                    fastcgi_split_path_info ^(/wordpress)(/.*)$;
            }
    

    Is that something I should add as well? What about the rest of the example code on that page?

  • For whatever reason, I can no longer go to site.com/anything

    anightinburlington.com/bars brings up a forbidden page. The home page works, and the entire dashboard works, but none of the pages after anightinburlington.com/ that don't pertain to the admin area.

    Any ideas?

  • So the WordPress installation is in /var/www/anightinburlington.com/public_html/wordpress but you want it served at the root domain? In that case you should just set the root to point right to the WordPress install. Like:

    server {
            listen 80 default_server;
            listen [::]:80 default_server ipv6only=on;
    
            root /var/www/anightinburlington.com/public_html/wordpress;
            index index.php index.html index.htm;
    
            server_name anightinburlington.com www.anightinburlington.com;
    
            location / {
                    # try_files $uri $uri/ =404;
                    try_files $uri $uri/ /index.php?q=$uri&$args;
            }
    
            location ~ \.php$ {
                    try_files $uri =404;
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
                    fastcgi_pass unix:/var/run/php5-fpm.sock;
                    fastcgi_index index.php;
                    include fastcgi_params;
            }
    }
    
  • Yeah, that's exactly my setup.

    I made those changes, which logically make sense, but now some pages are fixed, others are broken.

    I can now view all of the pages, except for anything in the wordpress dashboard. In addition, all of the image links are broken, and the css isn't rendering. On the bright side, the Yoast SEO xml sitemaps are now showing, which was another issue I had.

  • I've been stabbing at this for the last few hours, with no luck at all. I've tried everything from re-installing Wordpress files manually (perserving my wp-content / config), to renaming my theme - nothing works.

    From all the testing I'm seeing, the above config file just doesn't work. If it does work, than their must be a conflict between those settings, and my database, but I don't know. All I know is:

    -No css
    -Broken image links
    -Can't login (put in credentials, lead to a forbidden page)

    While I get that the sites-available file is essentially the .htaccess file I've worked with in the past, but for nginx, I'm completely knew to the rewrite rules of either, and have no idea where to go. I can basically read it, but I can't write it.

    Thanks for the help thus far, hopefully you or someone can send me in the right direction.

    EDIT

    In a guess and check fashion, I SEEM to have everything working. That being said, I'm shooting mostly blind with these educated guesses, so can anyone tell if this is correct / inform me of anything wrong with it? Sitemaps are showing, all pages are showing, no broken images, wordpress dashboard works.

    server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
    
        root /var/www/anightinburlington.com/public_html;
        index index.php index.html index.htm;
    
        server_name anightinburlington.com www.anightinburlington.com;
    
        location / {
                # try_files $uri $uri/ =404;
                try_files $uri $uri/ /wordpress$uri/ /index.php?q=$uri&$args;
        }
    
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
    
        error_page 404 /404.html;
    
        # redirect server error pages to the static page /50x.html
        #
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root /usr/share/nginx/html;
        }
    }
    

    I changed the root back to /var/www/anightinburlington.com/public_html;

    Then I added "/wordpress$uri/"

    Any thoughts?

Have another answer? Share your knowledge.