Nginx configuration parameters of WordPress blog

Source: Internet
Author: User
Tags wordpress blog

WordPress is a very popular Blog system. It can use Apache mod_rewrite to achieve static URL. After a persistent link is configured, a WordPress is generated under the root directory of the website (if writable. htaccess file, which can instruct Apache how to rewrite the URL (if the server is configured to allow the use of htaccess commands), its content is as follows:

# BEGIN WordPress
 
RewriteEngine On
RewriteBase/
RewriteCond % {REQUEST_FILENAME }! -F
RewriteCond % {REQUEST_FILENAME }! -D
RewriteRule./index. php [L]
 
# END WordPress
This file means that if the requested file does not exist, redirect the request to/index. php internally. WordPress analyzes the request URL to determine which page to display.

After Nginx + PHP is configured last time, because Nginx does not support Apache. htaccess files, to achieve persistent connection static, we must manually Configure Nginx files. First, find the Nginx configuration file. The default compiled configuration file is in/usr/local/nginx/conf/nginx. conf; the configuration file installed in Ubuntu through the package is located in/etc/nginx. conf. You can also edit the vhost configuration file, which is placed under/etc/nginx/sites-available.

The following is an example of basic configuration in Ubuntu ):

Location /{
Index index.html index. php;
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;
        }
    }
Location ~ . * \. Php $ {
Include/etc/nginx/fastcgi_params;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
    }
There are also many different configuration methods, such as not rewriting all URLs containing wp. This configuration contains the index file index.html and index. php in the directory. -F indicates whether the test file exists (regardless of the file and directory ),! -F indicates that it does not exist. When you rewrite urlto index.html, there is a break. When you rewrite it to index. php, there is no break. Because html files can be directly sent to the client without any extra work, the rewrite rule is terminated here, and nginx will directly send the files below. The. Php file needs to be further sent to the fastcgi process for running. Nginx will continue to judge that the file conforms to the second part of location ~ . * \. Php $ rules and perform FastCGI forwarding.

You can save the above content as wordpress. conf, and then apply the configuration file in your own vhost configuration, that is, the server section, for example (the configuration in Ubuntu is as follows ):

Server {
Listen 80;
Server_name 111cn.net * .111cn.net;
 
Root/var/www/111cn.net;
 
Include/etc/nginx/wordpress. conf;
}
Next, let Nginx re-load the configuration file to use the persistent link of WordPress.

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.