douyan5481 2014-04-08 17:26
浏览 246
已采纳

从Apache转换为Nginx + PHP-FPM后的Wordpress设置

I have a site that is hosted on a server that uses PHP, Apache. I would like to migrate this site another host that is running on PHP-FPM and Nginx. Obviously, changing the nameservers, mysql dump and transferring the actual wp folder is the easier part. But, I would like to know what settings to modify before migrating the site.

As far as I know, the only thing I have to worry about is pretty urls. I may be able to do try_files $uri $uri/ /index.php?$query_string; if it works. If not however, the I will risk the site being defaces for several hours before reversing the nameserver to it's original state.

  • 写回答

1条回答 默认 最新

  • duanjianxi8439 2014-04-08 17:36
    关注

    There is a great article here: http://codex.wordpress.org/Nginx on NGINX configs for Wordpress, here is the one I use for normal (not-multisite) wordpress. I save this in a separate file (wordpress.conf) and then include it in server blocks for wordpress-powered sites:

    location = /favicon.ico {
            log_not_found off;
            access_log off;
    }
    
    location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
    }
    
    # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
    location ~ /\. {
            deny all;
            access_log off;
            log_not_found off;
    }
    
    # Deny access to any files with a .php extension in the uploads directory
    location ~* ^/wp-content/uploads/.*.php$ {
            deny all;
            access_log off;
            log_not_found off;
    }
    
    # Deny access to any files with a .php extension in the uploads directory for multisite
    location ~* /files/(.*).php$ {
            deny all;
            access_log off;
            log_not_found off;
    }
    
    # WordPress single blog rules.
    # Designed to be included in any server {} block.
    
    # This order might seem weird - this is attempted to match last if rules below fail.                                                    
    
    # http://wiki.nginx.org/HttpCoreModule
    location / {
            try_files $uri $uri/ /index.php?$args;
    }
    
    # Add trailing slash to */wp-admin requests.
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    
    # Directives to send expires headers and turn off 404 error logging.
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
            expires 24h;
            log_not_found off;
    }
    
    # Uncomment one of the lines below for the appropriate caching plugin (if used).
    #include global/wordpress-wp-super-cache.conf;
    #include global/wordpress-w3-total-cache.conf;
    
    # Pass all .php files onto a php-fpm/php-fcgi server.
    location ~ \.php$ {
            # Zero-day exploit defense.
            # http://forum.nginx.org/read.php?2,88845,page=3
            # Won't work properly (404 error) if the file is not stored on this server, which is entirely possible with php-fpm/php-fcgi.
            # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on another machine.  And then cross your fingers that you won'
    t get hacked.
            try_files $uri =404;
    
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    
            include fastcgi_params;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_intercept_errors on;
            fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮