nginx+wordpress rewrite rules issues

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


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Of course, that entry was already there before trying to solve the url-IP/domain issue having the sites-available configuration file as follow: <br> <br>/etc/nginx/sites-available/mydomain.tld <br>-------------------------------------------------------- <br>#server { <br># server_name _; <br># rewrite ^ $scheme://www.mydomain.tld$request_uri last; <br>#} <br> <br>server { <br> #listen 80; ## listen for ipv4; this line is default and implied <br> #listen [::]:80 default_server ipv6only=on; ## listen for ipv6 <br> <br> root /usr/share/nginx/www/mydomain.tld; <br> index index.html index.htm index.php; <br> <br> include global/common.conf; <br> include global/wordpress.conf; <br> <br> server_name mydomain.tld www.mydomain.tld; <br> <br> location /doc/ { <br> alias /usr/share/doc/; <br> autoindex on; <br> allow; <br> allow ::1; <br> deny all; <br> } <br>} <br>-------------------------------------------------------- <br>(he rewrite-trick is currently commented) <br> <br> <br>For completeness ill add the included configuration files, may this will help. <br> <br>/etc/nginx/global/wordpress.conf <br>------------------------------------------------ <br>location / { <br> try_files $uri $uri/ /index.php?$args; <br>} <br> <br>location ~* /(?:uploads|files)/..php$ { <br> deny all; <br>} <br> <br>location ~ .php$ { <br> try_files $uri =404; <br> fastcgi_split_path_info ^(.+.php)(/.+)$; <br> fastcgi_pass unix:/var/run/php5-fpm.sock; <br> fastcgi_index index.php; <br> include fastcgi_params; <br>} <br> <br>rewrite /wp-admin$ $scheme://$host$uri/ permanent; <br> <br>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)$ { <br> access_log off; log_not_found off; expires max; <br>} <br>------------------------------------------------ <br> <br> <br>/etc/nginx/global/common.conf <br>--------------------------------------------- <br>listen 80; <br> <br>location = /favicon.ico { <br> log_not_found off; <br> access_log off; <br>} <br> <br>location = /robots.txt { <br> allow all; <br> log_not_found off; <br> access_log off; <br>} <br> <br>error_page 404 /404.html; <br> <br>error_page 500 502 503 504 /50x.html; <br> location = /50x.html { <br> root /usr/share/nginx/www; <br> } <br> <br>location ~ /. { <br> deny all; <br>} <br> <br>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)$ { <br> access_log off; log_not_found off; expires 30d; <br>} <br>--------------------------------------------- <br> <br> <br>

Shouldn’t need a rewrite rule. Have you tied something like this: <br> <br>server_name; <br>instead of <br>server_name _; ?