• Migrating from Centos + Apache to Centos + Nginx
    Got everything working except permalinks.

    Nginx.conf =

    #user  nobody;
    user  username;
    worker_processes  1;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    error_log  /path/to/place/error.log error;
    
    #pid        logs/nginx.pid;
    pid        /var/run/nginx.pid;
    
    events {
        worker_connections  1024;
        use epoll;
    }
    
    http {
    
        include       mime.types;
        default_type  app;
    
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
        #access_log  logs/access.log  main;
        access_log /path/to/access.log main;
            error_log  /path/to/error.log error;
    
        sendfile        on;
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
        keepalive_timeout  65;
    
        #gzipi  on;
    
        # Upstream to abstract back-end connection(s) for PHP
        upstream php {
            server unix:/var/run/php-fpm.sock;
        }
    # Added by me 08-12-2014
        server {
            listen       80;
            server_name  wptest    wptest.domain.com;
            root         /path/to/wordpress/;
            charset utf-8;
    
            location / {
                    index  index.php;
            }
    
    # using 'location /' breaks nginx
            location /path/to/wordpress/ {
                    try_files $uri $uri/ /index.php?$args;
            }
    
    # Testing alternative php conf info
    # Pass all .php files onto a php-fpm/php-fcgi server
            location ~ [^/]\.php(/|$) {
                    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
                    if (!-f $document_root$fastcgi_script_name) {
                    return 404;
            }
            # This is a robust solution for path info security issue and works with "cgi.fix_pathinfo = 1" in /etc/php.ini (default)
                    include fastcgi.conf;
                    fastcgi_index index.php;
    #               fastcgi_intercept_errors on;
                    fastcgi_pass php;
            }
        }

    rpm -qa | grep mysql returns:

    mysql-libs-5.1.69-1.el6_4.x86_64
    qt-mysql-4.6.2-26.el6_4.x86_64
    mysql-server-5.1.69-1.el6_4.x86_64
    mysql-5.1.69-1.el6_4.x86_64
    php-mysql-5.3.3-23.el6_4.x86_64

    rpm -qa | grep php returns:

    php-xml-5.3.3-23.el6_4.x86_64
    php-mbstring-5.3.3-23.el6_4.x86_64
    php-pear-1.9.4-4.el6.noarch
    php-cli-5.3.3-23.el6_4.x86_64
    php-gd-5.3.3-23.el6_4.x86_64
    php-5.3.3-23.el6_4.x86_64
    php-devel-5.3.3-23.el6_4.x86_64
    php-pdo-5.3.3-23.el6_4.x86_64
    php-pecl-apcu-4.0.2-2.el6.x86_64
    php-fpm-5.3.3-23.el6_4.x86_64
    php-mcrypt-5.3.3-1.el6.x86_64
    php-ldap-5.3.3-23.el6_4.x86_64
    php-mysql-5.3.3-23.el6_4.x86_64
    php-common-5.3.3-23.el6_4.x86_64

    Steps for migrating went as follows:

    mysqldump of original database
    tar cvzf of entire original wordpress directory
    Put existing wordpress installation into maintenance mode
    in mysql, created new db with same name and same user as original server
    edited wordpress db with following lines to update site url:
    update wp_options set option_value='https://wptest.domain.com' where option_name='home';
    update wp_options set option_value='https://wptest.domain.com' where option_name='siteurl';
    restarted mysql, php-fpm & nginx
    Logged into wptest.domain.com, installed search & replace plugin
    used it to replace all instances of wpold.domain.com with wptest.domain.com
    went to settings > permalinks > default
    menus all work, all pages load
    went to settings > permalinks > custom /%postname%/
    pages all show nginx 404 error pages.

    I’m pretty much 100% sure this is a nginx config issue but I’ve been at this for a couple of days now and it’s doing my head in. Can anyone offer any insight? suggestions? I’m thinking maybe even just typing all this out will possibly provide some new perspective on the thing and i’ll have a “d’oh” moment.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Not 100% sure but I’ve always had the root line without trailing slash. May be what’s breaking location /

    root /path/to/wordpress;

    then

    location / {
    		try_files $uri $uri/ /index.php$is_args$args;
    	}
    Thread Starter khaito

    (@khaito)

    Hey, thanks for the response. ??
    We’ve got other websites on this server that have root set with trailing slashes so don’t think it’s an issue. I think I fixed it though. I simplified all the php stuff down and merged the two location lines to this:

    server {
            listen       80;
            server_name  wptest    wptest.domain.com;
            root         /path/to/wordpress/;
            charset utf-8;
    
            location / {
                    index  index.php;
                    try_files $uri $uri/ /index.php?q=$uri&$args;
            }
    
            location ~ \.php$ {
                    try_files $uri =404;
                    include fastcgi_params;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    fastcgi_intercept_errors on;
                    fastcgi_pass    unix:/var/run/php-fpm.sock;
            }
        }

    This works for changing the permalinks now. ??

    Cheers!
    Robyn

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Yet another Apache > Nginx migration permalinks issue’ is closed to new replies.