Adding virtual hosts to nginx supports php pseudo-static

Source: Internet
Author: User
1. Add the vm to the usrlocalnginxconfvhost directory and create the virtual host configuration file demo.neoease.com. conf ({domain name}. conf). 2. Open the configuration file and add the following services: Export index. php; rootvar.

1. Add the VM to the/usr/local/nginx/conf/vhost directory and create the VM configuration file demo.neoease.com. conf ({domain name }. conf ). 2. open the configuration file and add the following services: server {listen 80; server_name demo.neoease.com; index index.html index.htm index. php; root/var

1. Add a VM

Go to the/usr/local/nginx/conf/vhost directory and create the virtual host configuration file demo.neoease.com. conf ({domain name}. conf ).

2. Open the configuration file and add the Service as follows:

server {    listen       80;    server_name demo.neoease.com;    index index.html index.htm index.php;    root  /var/www/demo_neoease_com;     log_format demo.neoease.com '$remote_addr - $remote_user [$time_local] $request'    '$status $body_bytes_sent $http_referer '    '$http_user_agent $http_x_forwarded_for';    access_log  /var/log/demo.neoease.com.log demo.neoease.com;}

3. Open the Nginx configuration file/usr/local/nginx/conf/nginx. confhttpThe VM configuration file is introduced as follows:

include vhost/*.conf;

This statement can also directly contain the address of the VM file, for example,/usr/local/nginx/conf/vhost/demo.neoease.com. conf.

4. Restart apache -- nginx

service nginx restart

Support for php

server {    listen       80;    server_name demo.neoease.com;    index index.html index.htm index.php;    root  /var/www/demo_neoease_com;     location ~ .*\.(php|php5)?$ {        fastcgi_pass unix:/tmp/php-cgi.sock;        fastcgi_index index.php;        include fcgi.conf;    }     log_format demo.neoease.com '$remote_addr - $remote_user [$time_local] $request'    '$status $body_bytes_sent $http_referer '    '$http_user_agent $http_x_forwarded_for';    access_log  /var/log/demo.neoease.com.log demo.neoease.com;}

Image anti-leech

Server {listen 80; server_name demo.neoease.com; index index.html index.htm index. php; root/var/www/demo_neoease_com; # Add a one-year expiration time for the image and prohibit Google, Baidu, and other websites from referencing the Image location ~ . *\. (Ico | jpg | jpeg | png | gif) $ {expires 1y; valid_referers none blocked demo.neoease.com * .google.com * .baidu.com; if ($ invalid_referer) {return 404 ;}} log_format comment '$ remote_addr-$ remote_user [$ time_local] $ request ''$ status $ response $ http_referer'' $ http_user_agent $ comment'; access_log/var/log/demo.neoease.com. log demo.neoease.com ;}

WordPress pseudo-static configuration ---------------If you set the WordPress link structure/%postname%/,/%postname%.htmlIn other formats, You need to rewrite the URL. WordPress provides Apache's. htaccess modification suggestions, but does not tell Nginx how to modify it. We can modify the WordPress virtual host configuration as follows:

server {    listen       80;    server_name demo.neoease.com;    index index.html index.htm index.php;    root  /var/www/demo_neoease_com;     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;        }    }    rewrite /wp-admin$ $scheme://$host$uri/ permanent;     location ~ .*\.(php|php5)?$ {        fastcgi_pass unix:/tmp/php-cgi.sock;        fastcgi_index index.php;        include fcgi.conf;    }     log_format demo.neoease.com '$remote_addr - $remote_user [$time_local] $request'    '$status $body_bytes_sent $http_referer '    '$http_user_agent $http_x_forwarded_for';    access_log  /var/log/demo.neoease.com.log demo.neoease.com;}

The LNMP kit provides the WordPress static configuration file/usr/local/nginx/conf/wordpress. conf, which can be referenced in the server range configured on the VM as follows.

include wordpress.conf;

If you use the LNMP suite, you will find the 404 page in the WordPress background, and the Diagonal Bar is missing behind wp-admin./Add the following statement at the end of wordpress. conf:

rewrite /wp-admin$ $scheme://$host$uri/ permanent;

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.