First off, I just setup a debian server with LEMP. I have a very special setup, which is one Wordpress installation in the root folder, and a Wordpress Multisite network which is installed in a subfolder called “/u”. The multisite network is served on subfolders too, not subdomains.
The current server is using Apache, which is setup this way. Main (single site, in root):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Redirect /login /u/login
Redirect /register /u/register
Redirect /link /u/link
Redirect /link-tv /u/link-tv
Redirect /wp-login.php /u/wp-login.php
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Multisite (subdir network, install in “/u”)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /u/
RewriteRule ^(([_0-9a-zA-Z-]+/)?)postpass/?$ /u/wp-login.php?action=postpass [QSA,L]
RewriteRule ^(([_0-9a-zA-Z-]+/)?)logout/?$ /u/wp-login.php?action=logout [QSA,L]
RewriteRule ^(([_0-9a-zA-Z-]+/)?)lostpassword/?$ /u/wp-login.php?action=lostpassword [QSA,L]
RewriteRule ^(([_0-9a-zA-Z-]+/)?)resetpassword/?$ /u/wp-login.php?action=resetpass [QSA,L]
RewriteRule ^(([_0-9a-zA-Z-]+/)?)signup/?$ /u/wp-login.php?action=register [QSA,L]
RewriteRule ^(([_0-9a-zA-Z-]+/)?)login/?$ /u/wp-login.php [QSA,L]
RewriteRule ^(([_0-9a-zA-Z-]+/)?)dashboard/?$ /u/wp-login.php [QSA,L]
</IfModule>
RewriteEngine On
RewriteBase /u
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
This Apache setup works great, but how do I convert this to work on Nginx?
All help is appreciated! Thanks!
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.
Click below to sign up and get $100 of credit to try our products over 60 days!
if (!-e $request_filename) { rewrite /wp-admin$ $scheme://$host$uri/ permanent; rewrite ^/u(/[^/]+)?(/wp-.) /u$2 last; rewrite ^/u(/[^/]+)?(/..php)$ /u$2 last; }
is that part necessary at all?
I think I solved it.
This is what I got:
Am I missing anything important?
Thank you! I read the guide and this is how far I have got:
And the restrictions.conf file:
This works for the main site, I can now navigate my main single Wordpress install which is in the root folder. However the Wordpress Multisite install which is located in folder “/u” is still broken.
Hi! As you can guess, your custom Apache config will take a little work to migrate to Nginx but it is 100% doable. Here’s an older tutorial with some good info to get started:
https://www.digitalocean.com/community/tutorials/how-to-migrate-from-an-apache-web-server-to-nginx-on-an-ubuntu-vps
Pay attention to the comments as there is some good info in there too, like this online converter for some of the rewrite rules:
https://winginx.com/en/htaccess
Hope this helps and if you get stuck please follow up in here and we’ll help you work through any issues if possible.
Good luck!