skip to Main Content

I am using the below NGINX configuration to serve a Laravel application and a WordPress blog. The blog used to be in a sub-domain (blog.example.com), but now moving to example.com/blog.

I am trying to separate both the Laravel application (/var/www/vhosts/example.com/httpdocs/laravel/public) and the WordPress (/var/www/vhosts/example.com/httpdocs/wordpress/) installations into different folders so it is easy to manage. The Laravel routes are working as expected, but the WordPress example.com/blog/wp-admin route is not working. Below is my NGINX configuration.

server {
    listen 80;
    server_name example.com;
    rewrite ^/(.*) https://example.com/$1 permanent;
}

server {
    listen 443 ssl;
    server_name example.com;

    charset utf-8;

    ssl    on;
    ssl_certificate     /etc/ssl/example.crt;
    ssl_certificate_key /etc/ssl/example.key;

    root /var/www/vhosts/example.com/httpdocs/laravel/public;
    index index.html index.htm index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 403 /index.php;
    error_page 404 /index.php;

    location ~ .php$ {
        fastcgi_split_path_info ^(.+.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_read_timeout 180;
        include fastcgi_params;
    }

    ## WordPress blog configuration
    location ^~ /blog/ {
        alias  /var/www/vhosts/example.com/httpdocs/wordpress/;

         if (!-e $request_filename) {
            rewrite ^ /blog/index.php last;
        }

        try_files $uri $uri/ /blog/index.php;

        location ~ .php$ {
            fastcgi_split_path_info ^(/blog)(/.*)$;
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            fastcgi_read_timeout 180;
            include fastcgi_params;
         }
    }

    location ~ /.(?!well-known).* {
        deny all;
    }
}

Please could you point me, why I am unable to access wp-admin? Is there a better way to do this? Thanks

3

Answers


  1. Chosen as BEST ANSWER

    My bad just realised that there is a WordPress plugin named wps-hide-login that prevented using the wp-admin route. Once I renamed the plugin folder, I managed to login OK. Thank you for all your inputs.


  2. Try to do that. Sets the "root" for /blog/ and removes /blog/ from the rewrite.

    And also remove the slash at the end of the root directory /xyz/wordpress;

     root /var/www/vhosts/example.com/httpdocs/wordpress;
     
     rewrite .* /index.php last;
     
     try_files $uri $uri/ /index.php;
    
    Login or Signup to reply.
  3. If you have installed a new wordpress at the new folder location then it will not cause any issue.

    But if you are moving existing wordpress site to the new folder location then you may need to check your existing .htaccess file.

    You may first need to modify the site url in the wordpress table to match with new location and also check the WP settings for permalink. Hope this will solve the issue.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search