How to solve the 500 error when WordPress is migrated to Nginx

Source: Internet
Author: User
Tags chmod memcached php file

After wordpress is migrated from apache to nginx, it cannot be opened after the database configuration is correct. Check the http status and the result returns 500, as shown in the figure below:

A similar error occurs when the. htaccess configuration in apache is incorrect. The following error occurs:

Location /{
If (-f $ request_filename/index.html ){
Rewrite (. *) $1/index.html break;
        }  
If (-f $ request_filename/index. php ){
Rewrite (. *) $1/index. php;
        }  
If (! -F $ request_filename ){
Rewrite (. *)/index. php;
        } 

If the pseudo-static rule is disabled, it cannot be opened. A new wordpress is installed, and the above pseudo-static rule can be used for normal access, proving that the pseudo-static rule is correct.

If the homepage can be opened, but the internal page cannot be opened, it is likely to be a pseudo-static problem. You can view: in linux nginx, the WordPress pseudo-static settings solve the problem that only the homepage can be opened but cannot open the internal page.

Then I suddenly found that the php file was not executable. I suspect this was the cause. So I added the executable attribute to all the php files, but it still didn't work. Check the newly installed wordpress, php runs well without executable properties, which does not seem to be the cause. Although this method does not solve the problem, it is also rewarding. Use chmod 755-R *. php cannot add executable attributes to all php files in the current directory and sub-directories as expected. The correct method should be:

Find path-type f-exec chmod 755 {}\;

{} Is to pass the find results one by one to chmod as the parameter, semicolon ";" is a required parameter of-exec, telling exec that the command is over, "; "is also the keyword of shell command end, so escape or reference is required, that is, you can also write:

Find path-type f-exec chmod 755 {}";"

Later through the search found that the cache plug-in will have an impact, just think of their own installed object-cache plug-in, the object-cache.php removed, it can be accessed normally, however, I didn't say that the object-cache cannot be used in nginx. Do I have to restart memcached?

Memcached has not been installed !!!!

Software: memcached-1.4.5-1.el5.kb.i386.rpm
Nginx-1.0.15.tar.gz
Agentzh-memc-nginx-module-v0.13rc3-1-gee3fe43.tar.gz
Agentzh-srcache-nginx-module-v0.13rc6-6-g01829d9.tar.gz
Ngx_http_upstream_keepalive-d9ac9ad67f45.tar.gz (I will provide these software to you)

1. Install memcached


Rpm-ivh memcached-1.4.5-1.el5.kb.i386.rpm

I'm a little late and don't want to compile and install memcached. if you want to change your mind, you can go to the tar.gz package of memcachedto compile and install it.
Start memcached
Memcached-d-m 10-u root-l 192.168.10.5-p 11211-c 256-P/tmp/memcached. pid

2. Compile nginx and install the 3rd module package

./Configure -- user = nginx -- group = nginx -- add-module = ../agentzh-memc-nginx-module-ee3fe43 \
-- Add-module = ../agentzh-srcache-nginx-module-01829d9 -- add-module = ../ngx_http_upstream_keepalive-d9ac9ad67f45 \
-- Prefix =/usr/share/nginx -- sbin-path =/usr/sbin/nginx -- conf-path =/etc/nginx. conf \
-- Error-log-path =/var/log/nginx/error. log -- http-log-path =/var/log/nginx/access. log \
-- Http-client-body-temp-path =/var/lib/nginx/tmp/client_body -- http-proxy-temp-path =/var/lib/nginx/tmp/proxy -- http-fastcgi-temp-path =/var/lib/nginx/tmp/fastcgi \
-- Pid-path =/var/run/nginx. pid -- lock-path =/var/lock/subsys/nginx -- with-http_secure_link_module \
-- With-http_random_index_module -- with-http_ssl_module -- with-http_realip_module -- with-http_addition_module \
-- With-http_sub_module -- with-http_dav_module -- with-http_flv_module -- with-http_gzip_static_module \
-- With-http_stub_status_module -- with-http_perl_module -- with-http_geoip_module -- with-mail \
-- With-mail_ssl_module -- with-cc-opt =-O3 -- with-cpu-opt = pentium

If a compilation error occurs, you can refer to this article to compile and install nginx and modify the version header information.

Make & make install

3. Configure nginx

User nginx;
Worker_processes 2;
Worker_cpu_affinity 0001 0010;
Worker_rlimit_nofile 65535;

Error_log/var/log/nginx/error. log;

Pid/var/run/nginx. pid;

Events {
Use epoll;
Worker_connections 65535;
}

Http {
Include mime. types;
Default_type application/octet-stream;
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/var/log/nginx/access. log main;

Server_names_hash_bucket_size 128;
Client_header_buffer_size 4 k;
Large_client_header_buffers 4 32 k;
Client_body_in_file_only clean;
Client_max_body_size 8 m;

Sendfile on;
Tcp_nopush on;

Keepalive_timeout 60;
Tcp_nodelay on;
Server_tokens off;

Fastcgi_connect_timeout 300 s;
Fastcgi_send_timeout 300 s;
Fastcgi_read_timeout 300 s;
Fastcgi_buffer_size 128 k;
Fastcgi_buffers 8 128 k; #8 128
Fastcgi_busy_buffers_size 256 k;
Fastcgi_temp_file_write_size 256 k;
Fastcgi_intercept_errors on;
 
# Hiden php version
Fastcgi_hide_header X-Powered-;

Gzip on;
Gzip_min_length 1 k;
Gzip_buffers 4 16 k;
Gzip_http_version 1.0;
# Gzip_disable "MSIE [1-5] \.";
Gzip_comp_level 4;
Gzip_types text/plain application/x-javascript text/css application/xml image/gif image/jpg image/jpeg image/png;
# Gzip_vary on;
Proxy_hide_header Vary;

# Memcache Service upstream
Upstream memcache {
Server 192.168.10.5: 11211;
Keepalive 512 single;
        }

Server {
Listen 80;
Server_name blog.slogra.com;
# Memc-nginx-module
Location/memc {
Internal;
Memc_connect_timeout 100 ms;
Memc_send_timeout 100 ms;
Memc_read_timeout 100 ms;
Set $ memc_key $ query_string;
Set $ memc_exptime 300;
Memc_pass memcache;
        }
Location /{
Root/var/www/vhosts/blog.slogra.com;
Index. php index.html index.htm;
# Srcache-nginx-module
Set $ key $ uri $ args;
Srcache_fetch GET/memc $ key;
Srcache_store PUT/memc $ key;
   
Location ~ . * \. (Php | php5 )? $ {
Fastcgi_pass unix:/tmp/php-cgi.sock;
Fastcgi_index index. php;
Include fastcgi. conf;
        }
        }
    }
}

Ps:
Memc-nginx is a standard upstream module. Therefore, you must first define the upstream of memcache.
Here, I started a memcache service on the local machine. The port is 11211 by default, and the keepalive command is provided by http-upsteram-keepalive-module, here, we can maintain a maximum of 512 connections that are not immediately closed to improve performance.

The following is the configuration location for memc-nginx-module. We configure it to/memc. All requests request this location to operate memcache.
Memc-nginx-module access to memcache is based on the http method syntax. The GET and PUT methods of http are used to represent the set and DELETE methods.
Here, we set/memc as internal to accept only internal access and not external http requests. This is for security consideration. Of course, if you need to open external access through the http protocol, you can remove internal and use deny and allow to control permissions. the variable $ memc_key indicates what is used as the key. Here, we use the $ query_string embedded in Nginx as the key. $ memc_exptime indicates the cache Expiration Time, which is recorded in seconds. the value is set to 300 (5 minutes). In actual application, you can set different expiration times for different content based on the actual situation.

Finally, we configured the cache for the location "/", which indicates that all requests will be cached. Of course, this is only required by the example. In practice, this is generally not the case, instead, configure the cache for the specific location to be cached. for example, cache only images, js, css, and other resource files.

Srcache_fetch indicates registering an input interception processor to the location. This configuration will be executed when the location enters;
Srcache_store indicates registering an output interceptor to the location. When the location execution is complete and the output is executed.
Note that the srcache module can be used with any caching module instead of memc. Here we use $ uri $ args as the cache key.

After the preceding configuration, the following logic is added to Nginx: when the requested uri is at the end of "php", first go to memcache to check whether there is data with $ uri $ args as the key. If yes, return directly. Otherwise, run the location logic. If the returned http status code is

After installing memcached, you can finally access it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.