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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了
  • ¥15 电脑最近经常蓝屏,求大家看看哪的问题
  • ¥60 高价有偿求java辅导。工程量较大,价格你定,联系确定辅导后将采纳你的答案。希望能给出完整详细代码,并能解释回答我关于代码的疑问疑问,代码要求如下,联系我会发文档
  • ¥50 C++五子棋AI程序编写
  • ¥30 求安卓设备利用一个typeC接口,同时实现向pc一边投屏一边上传数据的解决方案。
  • ¥15 SQL Server analysis services 服务安装失败