Migrated from ISPConfig+Apache to ISPConfig+NGINX

Discussion in 'Installation/Configuration' started by Robert Craig, Sep 7, 2024.

  1. Robert Craig

    Robert Craig New Member

    I have a problem and I am unsure how to approach it. I have migrated a number of wordpress websites that were on an Apache config to a new server using NGINX.

    Unfortunately none of the sites appear to be running :(

    Any pointers to how to troubleshoot would be appreciated.

    thanks.
     
  2. Robert Craig

    Robert Craig New Member

    i discovered that the ssl certificates had not applied so this meant that the sites would not display as they are set to use SSL.

    I do have the issue of them not being able to use pretty URLs though. If I click on any links from the home pages I get a 404 error. Any ideas?
     
  3. Robert Craig

    Robert Craig New Member

    and the URLs are working now! Dunno if the change to nginx was worth the pain lol
     
  4. Robert Craig

    Robert Craig New Member

    I seem to have an issue with the server being able to write to files and create files :(
     
  5. michelangelo

    michelangelo Active Member

    Apache is using .htaccess files to handle f.e. pretty URLs but .htaccess files are not supported by Nginx!
    For Nginx you need to set up the rewrite rules yourself in ISPConfig, see options tab of the web.
     
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    How did you do the migration?
    Did you take care to use the same let's encrypt client on old and new installation?

    Chcek that your harddisk is not full. E.g. use the command:

    df -h
     
  7. concept21

    concept21 Active Member

    If you have access to manage your sites' configurations, then choose Nginx and do anything on your own server.
    If you are on sharing hosting, choose Apaches.
     
    Robert Craig likes this.
  8. Robert Craig

    Robert Craig New Member

    Thanks for getting back to me. I was panicking really. There is 1TB of space so it wasnt a HD space issue. It was mostly me and stress, never a good combination.

    Migration was a straight scp copy from one VPS to the other once i had ISPConfig installed. Then I chown'd the web folders within each defined site. A reboot fixed the perms issue. I put it all down to settling in :)

    Lets Encrypt was ok once the DNS had caught up.


    Anyways all good now - thanks once again!
     
  9. Robert Craig

    Robert Craig New Member

    Ive always used apache and thought it was time to try NGINX as I have heard good things about it and wanted to give it a go. Like everything new though it was a journey to configure it. Glad to say I am comfortable in my new VPS using NGINX now.
     
  10. ahrasis

    ahrasis Well-Known Member HowtoForge Supporter

    Welcome to ISPConfig with Nginx.

    I myself have migrated almost a decade ago, with lot to learn at first but it becomes easier and easier thereafter.

    I however did not migrate from a setup to another but rather use Florian's old guide for that, so that used to work, but may be some adjustments are needed for recent setup.

    https://blog.schaal-24.de/ispconfig/ispconfig-apache-durch-nginx-ersetzen/?lang=en
     
  11. Robert Craig

    Robert Craig New Member

    I have come across an issue and I just cant seem to solve it...

    I have DevKinsta locally and use that to develop wordpress installs. I have a current plugin that uses a route to trigger an image rendering routine. This works fine on DevKinsta using the following nginx site config

    Code:
    server {
      set $site_name framer;
      set $php_path devkinsta_fpm:9003;
    
      listen 80;
      listen [::]:80;
      listen 443 ssl http2;
      listen [::]:443 ssl http2;
    
      ssl_certificate /www/kinsta/ssl/framer.local.crt;
      ssl_certificate_key /www/kinsta/ssl/framer.local.key;
    
      server_name  framer.local *.framer.local;
      access_log   /www/kinsta/logs/framer_access.log main;
      error_log    /www/kinsta/logs/framer_error.log;
    
      root /www/kinsta/public/framer;
      index index.php index.html;
    
      include multisite_subdir.conf;
    
      location / {
          try_files $uri $uri/ /index.php?$args;
      }
    
      ## Add the new route rewrite for image files only 
      location ~ ^/render/(.+\.(jpg|jpeg|png|gif|webp|bmp))$ {
          rewrite ^/render/(.+)$ /wp-json/f4f-framer/v1/render/$1 last;
      }
    
      location ~ \.php$ {
          fastcgi_split_path_info ^(.+?\.php)(/.*)$;
          if (!-f $document_root$fastcgi_script_name) {
            return 404;
          }
          include fastcgi_params;
          fastcgi_param PHP_ADMIN_VALUE "[email protected]";
          fastcgi_intercept_errors on;
          fastcgi_pass $php_path;
          fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
      }
    
    }

    However I am not getting the nginx Directives in Options to work on ISPConfig and am now wondering if the approach is wrong. This is my options

    Code:
    location / {
        try_files $uri $uri/ /index.php?$args;
    }
    
    ## Add the new route rewrite for image files only
    location ~ ^/render/(.+\.(jpg|jpeg|png|gif|webp|bmp))$ {
        rewrite ^/render/(.+)$ /wp-json/f4f-framer/v1/render/$1 last;
    }
    
    # Add trailing slash to */wp-admin requests.
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    
    location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ {
        expires max;
        log_not_found off;
    }
    
    Does anyone know why it is not working? I am getting a 404 page not found when trying to access a image url that is rendered e.g.

    https://g2.first4frames.co.uk/rende...ICO-JF-40-Ardbeg-Distillery-Isle-of-Islay.jpg
     
  12. till

    till Super Moderator Staff Member ISPConfig Developer

    It looks fine to me so far what you added to the Nginx directives field. Have you checked the site's access and error.log for the exact error messages? Have you checked that the vhost file of the site has not been saved with .err file ending in the nginx sites-available folder? If you are locally developing on Windows, then you must be aware that on Linux, e.g., Image.jpg and Image.jpg are different files, while Windows is not case sensitive, and therefore, it's the same file on Windows. Also, take care that you uploaded all required WP files and images.
     
  13. Robert Craig

    Robert Craig New Member

    I develop entirely on linux locally and the server is also linux - I am very familiar with file name case etc :) There are no errors and no debug.log in wordpress. So I can only assume that the route is not working. Im at a bit of a loss on how to trouble shoot this.
    if the rewrite was working I wouldnt be getting a 404 error. The file does not exist so normally 404 would be correct. So the rewrite has to happen in order to make sure that the image is generated on the fly and handed back to the browser as a render image using php. If the render errors then it produces a placeholder image. If that makes sense.
     
    Last edited: Sep 24, 2024
  14. till

    till Super Moderator Staff Member ISPConfig Developer

    Have you checked the domain.vhost file that ISPConfig generates to see if it contains the snippet?
     
  15. Robert Craig

    Robert Craig New Member

    yes the snippet is in the vhost file. I deleted the error file and restarted nginx and there are no errors in doing that also. So it is happy with the config file.

    I am wondering if it is something to do with wordpress and registering routes.

    Code:
    register_rest_route('f4f-framer/v1', '/render/(?P<path>.+)', array(
    'methods' => 'GET',
    'callback' => array( $image_controller, 'render_image' ),
    'permission_callback' => '__return_true',
    ));
    
    the above will create a route /wp-json/f4f-framer/v1/render/...

    Perhaps NGINX is not honouring the dynamically added routes in wordpress?
     
    Last edited: Sep 24, 2024
  16. Robert Craig

    Robert Craig New Member

    removing this fixed it...

    Code:
    location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ {
    expires max;
    log_not_found off;
    }
    
    This was after the first rule so I am not sure why that was causing an issue. Anyways fixed now - at least it is if no one says I should still have that in the config!
     
  17. till

    till Super Moderator Staff Member ISPConfig Developer

    Removing that is okay; it just sets the expiry time and disables logging for not-found errors for images.
     

Share This Page