Nginx server binds multiple domain names, supports pathinfo routing, hides index.php portal files

Source: Internet
Author: User
Tags nginx server

This article is only for operation, explain the explanation section to be updated.

1. Modify Nginx configuration file (my profile is in/etc/nginx/nginx.conf)

[[Email protected] ~] # Find/-name nginx.conf      
[[Email protected] ~] # vim/etc/nginx/nginx.conf    
Nginx. approximate structure of the Conf configuration file:... http{    server{    ...                        #一个server结构可以对应一个域名    }      include vhosts/*conf    # Add this sentence, all new domain names can be placed under/etc/nginx/vhosts/, easy to manage separately, note that the Vhosts directory needs to be created }

2. In the/etc/nginx/vhosts/directory, add a new domain configuration file xincanzhe.conf (this way I want to bind a www.xincanzhe.top domain name), Copy the server section in nginx.conf to xincanzhe.conf

Server {Listen80; server_name www. Xincanzhe.top; #新增域名名称#CharSet koi8-r;Access_log/data/wwwlogs/www.xincanzhe.top.Logcombined; #设置访问该域名产生的日志文件, location is automatically generated when no settings are created /{root/data/wwwroot/xincanzhe/ Public/; #域名指向的根目录Index Index. HTML index.php Index.htm; #隐藏index. PHP            if(!-E$request _filename) {rewrite^ (. *) $/index.php?s=/$1Last ;  Break; }        }        #error_page 404/404.html;        #Redirect Server error pages to the static page/50x.html        #Error_page 502 503 504/50x.html; Location=/50x.HTML {root HTML; }        #Proxy The PHP scripts to Apache listening on 127.0.0.1:80        #        #Location ~ \.php$ {        #Proxy_pass http://127.0.0.1;        #}        #Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000        #Location ~ \.php$ {root/data/wwwroot/xincanzhe/ Public/; #域名指向的根目录Fastcgi_pass127.0.0.1:9000; Fastcgi_index Index.PHP; #使Nginx支持pathinfo路由Fastcgi_split_path_info ^ (. +\.php) (. *) $;#增加这一句Fastcgi_param Path_info$fastcgi _path_info;#增加这一句Fastcgi_param Script_filename$document _root$fastcgi_script_name; includeFastcgi_params; }        #deny access to. htaccess files, if Apache ' s document Root        #concurs with Nginx ' s one        #        #Location ~/\.ht {        #deny all;        #}}

3. If you need to add a new domain name again, simply create a new profile in/etc/nginx/vhosts/.

Nginx server binds multiple domain names, supports pathinfo routing, hides index.php portal files

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.