Linux Nginx virtualhost Virtual host multi-site setup

Source: Internet
Author: User
Tags nginx server

an nginx server the same IP is registered multiple different domain names, access to different domain names to the server after the request for different projects the IP address of the Nginx server192.168.155.129assuming that the server has two project Websuit_a,websuit_b, client access websuit_a. com when you request a websuit_a project, Access Websuit_b.com when requesting a Websuit_b project first create a new project folder under the project root directory websuit_a and Websuit_b programs that store two virtual sitesmkdir-m777-p/usr/local/nginx/html/websuit_a/usr/local/nginx/html/websuit_b New Index under the WEBSUIT_A project.php file, and enter the following content<?phpEcho"This is Websuit_a";? >Vim/usr/local/nginx/html/websuit_a/index.PHP creates a new index under the Websuit_b project.php file, and enter the following content<?phpEcho"This is Websuit_b";? >Vim/usr/local/nginx/html/websuit_b/index.PHP creates a new vhosts_conf folder within the Nginx configuration folder to store configuration files for different virtual sitesmkdir-m777-p/usr/local/nginx/conf/vhosts_conf Create websuit_a in the insideThe configuration file for the. com site, named Websuit_a.conf Edit fill in the following contents to save the server {Listen80;#port number of the listenerserver_name websuit_a.com;#Client access to incoming domain name    #access_log Logs/host.access.log main;Location/{root HTML/websuit_a;#the site's project path can also be filled with an absolute path/usr/local/nginx/html/websuit_aIndex index.html index.htm Index.PHP; #The site's rewrite is written here, and URL rewriting is the process of getting an incoming URL request and then re-writing it to another URL that the site can handle.Rewrite ^/(\w+) \.html$/$1.PHP; Rewrite^/(\w+)/(\w+) $/$1/$2.PHP; }    #configuration of the error pageError_page 404/404.html; Error_page502 503 504/50x.html; Location=/50x.HTML {root HTML; }    #Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000Location ~ \.php$ {root HTML/websuit_a; Fastcgi_pass127.0.0.1:9000; Fastcgi_index Index.PHP; Fastcgi_param Script_filename/usr/local/nginx/html/websuit_a$fastcgi _script_name; includeFastcgi_params; } Location~ /\.HT {deny all; }}vim/usr/local/nginx/conf/vhosts_conf/websuit_a.conf re-create Websuit_bThe configuration file for the. com site, named Websuit_b.conf Edit fill in the following contents to save the server {Listen80;#port number of the listenerserver_name websuit_b.com;#Client access to incoming domain name    #access_log Logs/host.access.log main;Location/{root HTML/websuit_b;#the site's project path can also be filled with an absolute path/usr/local/nginx/html/websuit_bIndex index.html index.htm Index.PHP; #rewrite of the site is written hereRewrite ^/(\w+) \.html$/$1.PHP; Rewrite^/(\w+)/(\w+) $/$1/$2.PHP; }    #configuration of the error pageError_page 404/404.html; Error_page502 503 504/50x.html; Location=/50x.HTML {root HTML; }    #Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000Location ~ \.php$ {root HTML/Websuit_b; Fastcgi_pass127.0.0.1:9000; Fastcgi_index Index.PHP; Fastcgi_param Script_filename/usr/local/nginx/html/websuit_b$fastcgi _script_name; includeFastcgi_params; } Location~ /\.HT {deny all; }}vim/usr/local/nginx/conf/vhosts_conf/websuit_b.conf shutdown nginx service nginx stop Edit nginx config file add the following to the last line in the HTTP {} blockinclude/usr/local/nginx/conf/vhosts_conf/*. conf;vim/usr/local/nginx/conf/nginx.conf start Nginxservice nginx start because it is not outside the network environment, only local access, so modify the client hosts file, Add the following two items 192.168.155.129 websuit_a.com192.168.155.129 websuit_b.com Enter websuit_a.com,websuit_b.com respectively on the client browser to display this Is Websuit_a,this are websuit_b

Linux Nginx virtualhost Virtual host multisite settings

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.