2014-04-08 17:26
浏览 201

从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.

图片转代码服务由CSDN问答提供 功能建议

我有一个托管在使用PHP,Apache的服务器上的站点。 我想迁移此站点另一个在PHP-FPM和Nginx上运行的主机。 显然,更改名称服务器,mysql转储和传输实际的wp文件夹是更容易的部分。 但是,我想知道在迁移网站之前要修改哪些设置。

据我所知,我唯一需要担心的是漂亮的网址。 我可以做 try_files $ uri $ uri / /index.php?$query_string; 如果有效的话。 但是,如果没有,那么在将名称服务器转换为原始状态之前,我将冒险将网站污损几个小时。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanjianxi8439 2014-04-08 17:36

    There is a great article here: 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.                                                    
    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.
            # 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;
    点赞 打赏 评论

相关推荐 更多相似问题