nginx+wordpress rewrite rules issues

Posted March 12, 2014 11.3k views
Hello I think I've run into a bad written configuration files issue, but first of all my configuration: Current config: Debian nginx php php-fpm APC MariaDB wordpress Cause of the problem encountered: after installing all the said components, the wordpress site was working well, but the url displayed the IP as the domain name of my site instead of the correct "mydomain.tld" or "www.mydomain.tld". I managed to solve this putting the following rewrite rule in the main config file of my site in /sites-available server { server_name _; rewrite ^ $scheme://www.mydomain.tld$request_uri last; } BUT, having this rule active locks me out of the wordpress administration page (mydomain.tld/wp-admin/) in a way that seems to be that this rule triggers a loop during the authentication process at "mydomain.tld/wp-login.php" page redirecting at the same page (wp-login.php). I'd say im new in nginx managing and i want to figure out what the #?@! is wrong thanks for all suggestions Mars

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers
Shouldn't need a rewrite rule. Have you tied something like this:

instead of
server_name _; ?
Of course, that entry was already there before trying to solve the url-IP/domain issue having the sites-available configuration file as follow:

#server {
# server_name _;
# rewrite ^ $scheme://www.mydomain.tld$request_uri last;

server {
#listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6

root /usr/share/nginx/www/mydomain.tld;
index index.html index.htm index.php;

include global/common.conf;
include global/wordpress.conf;

server_name mydomain.tld www.mydomain.tld;

location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow ::1;
deny all;
(he rewrite-trick is currently commented)

For completeness ill add the included configuration files, may this will help.

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

location ~* /(?:uploads|files)/.*\.php$ {
deny all;

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;

rewrite /wp-admin$ $scheme://$host$uri/ permanent;

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;

listen 80;

location = /favicon.ico {
log_not_found off;
access_log off;

location = /robots.txt {
allow all;
log_not_found off;
access_log off;

error_page 404 /404.html;

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;

location ~ /\. {
deny all;

location ~* ^.+\.(js|css|swf|xml|txt|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 30d;