WordPress and Drupal nginx configuration rewrite rewrite rule example _nginx

Source: Internet
Author: User
Tags php language drupal nginx server

Wordpress

WordPress is still the world's most popular blog system, more and more by the WordPress built Web site in the use of Nginx Server Software, here to share the WordPress nginx rewrite rules:

  server {Listen 80;
    server_name www.jb51.net jb51.net;
 
    Access_log/data/logs/nginx/www.jb51.net.access.log main;
    Index index.html index.php;
Root/data/site/www.jb51.net;
    Location/{try_files $uri $uri//index.php $args;
    Add_header Pragma "public";
Expires 12h;
 
rewrite/wp-admin$ $scheme://$host $uri/permanent; Location ~* ^.+\. (ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|
      MID|MIDI|WAV|BMP|RTF) $ {access_log off;
      Log_not_found off;
Expires Max;
 
    } location ~ \.php$ {try_files $uri = 404;
    Fastcgi_split_path_info ^ (. +\.php) (/.+) $;
    #NOTE: 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 127.0.0.1:9000; } location ~. *\.
  (gif|jpg|jpeg|png|bmp|swf) $ {expires 24h;  Access_log off; } location ~. *\.
    (JS|CSS) $ {expires 24h;
Access_log off;
 }

You can restart your nginx.

Drupal Nginx Rewrite rules
Drupal is written in PHP language open source Content Management framework, is commonly known as CMS, many people are using Drupal to build their own blog, here also to share the Nginx rewrite rules Drupal:

server {
 ...
Location/{# This are cool
 because no PHP are touched for static content
 try_files $uri @rewrite;
 }
Location @rewrite {
 # Some modules enforce no slash (/) at the "End of" the URL
 # Else this rewrite block wouldn ' t b E needed (globalredirect)
 rewrite ^/(. *) $/index.php?q=$1;
Location ~ \.php$ {
 fastcgi_split_path_info ^ (. +\.php) (/.+) $;
 #NOTE: should have "cgi.fix_pathinfo = 0;" In php.ini
 include fastcgi_params;
 Fastcgi_param script_filename $document _root$fastcgi_script_name;
 Fastcgi_intercept_errors on;
 Fastcgi_pass unix:/tmp/phpfpm.sock;
 }
...
 }


Restart Nginx

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.