Nginx virtual host configuration example method

Source: Internet
Author: User

Open the nginx installation directory/conf/nginx. conf file, find the http curly brackets, and add the following code.

The code is as follows: Copy code

Server
  {
Listen 80; # port, which is usually the default value (required)
Server_name www.111cn.net 111cn.net; # domain name. Multiple domain names are separated by spaces (required)
Index index.html index.htm index. php; # default homepage document. Multiple documents can be added (required)
Root/data0/htdocs/www.111cn.net; # VM Directory (required)

# -- Automatically complete www (not necessary) before the domain name )--#
If ($ host! = 'Www .111cn.net '){
Rewrite ^/(. *) $ http://www.111cn.net/#1 permanent;
    }
# -- Domain name completion --#

# -- For WordPress pseudo-static -- (optional )--#
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;
    }
# -- WordPress pseudo-static end --#

# -- PHP support -- if you build a PHP environment, add this section --#
Location ~ . *. (Php | php5 )? $
    {
# Fastcgi_pass unix:/tmp/php-cgi.sock;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fcinclude GI. conf;
    }
# -- PHP support end --#

# -- Additional configuration. It is best to remove this configuration if it is run online. For example, the first line indicates opening the search (insecure )--#
Autoindex on;
Autoindex_exact_size off;
Autoindex_localtime on;
# -- Additional configuration --#

# Log on (latest version format)
Access_log/data1/logs/access_qttc.log logs;
  }

Copy the above code to nginx. conf and save and restart nginx to take effect.

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.