WordPress admin redirecting on Nginx
Wordpress

WordPress admin redirecting on Nginx

I had an odd problem this morning.  I moved my blog over to a new VPS last week, switching from Apache to Nginx w/ PHP-FPM 7.  But when I tried to log in this morning to do a quick blog post on starting Solr on CentOS 7 (which I eventually did not do) but I found that I was getting infinite redirects on my login page.  Turns out that my Nginx configuration was wrong.  Following is the Nginx configuration I had

server {
 listen 80;
 server_name eschrade.com www.eschrade.com;
 root <root>;
 index index.php;
location / {
try_files $uri $uri/ /index.php;
 if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
 }
 location ~* \.(gif|jpg|png)$ {
    expires 30d;
  }
  location ~* \.php$ {
   fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
   include fastcgi_params; ## See /etc/nginx/fastcgi_params
  }
}

Following is the configuration that works.  It is a very slight change (try_files) but it apparently makes a world of difference.

server {
 listen 80;
 server_name eschrade.com www.eschrade.com;
 root <root>;
 index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
 if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
 }
 location ~* \.(gif|jpg|png)$ {
    expires 30d;
  }
  location ~* \.php$ {
   fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
   include fastcgi_params; ## See /etc/nginx/fastcgi_params
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *