nginx configure name-based virtual hosting

Article Source

Operation and maintenance Guild: nginx configure name-based virtual hosting

1 , What is Web Hosting

Hosting using special techniques, to a server running on the host computer into a plurality of logic. So it was to make programs run multiple Web sites on a single physical server so that the server can use up the remaining space. Give full play to the role of the server. Between virtual hosts is completely independent.

So when using the nginx web platform to build, only need to use a nginx software, you can run multiple ip-based or based website domain names.

 

2 , name-based virtual hosting

This domain name-based virtual hosting is the most commonly used. Generally use the internal network ip based.

(1) nginx.conf configuration

Just add on the bottom of the field in the nginx.conf.

include vhosts/*.conf;

Add on top of the field as long as you can at http module.

Then create vhosts directory of nginx conf directory, if you do not create.

 

(2) add a virtual host configuration file

Add clear in vhosts directory .conf configuration file, the name of any of the cases, the best and deploy applications with the name relations, to facilitate later maintenance.

To the previous configuration, for example

1.png

server {

        listen 80;         

# Configure port monitoring, as long as 80 can be configured, regardless of how many virtual hosts are used to write 80 ports

        server_name ebook.yunweigonghui.com;

        # This is the most important and the name required.

        root /usr/local/ywgh/nginx/html/wp/;

              # Write clearly project path, this is also very important, do not misconfigured.

        access_log /usr/local/ywgh/nginx/logs/wp/access.log main;

        # Access log write clearly, can not write, in a production environment, you must configure clear, log independence.

location ~ \.php$ {

                try_files $uri =404;

                fastcgi_pass 127.0.0.1:9000;

                error_log /usr/local/ywgh/nginx/logs/wp/php-error.log;

                include fastcgi.conf;

                fastcgi_index index.php;

        }

              # Top is configured in relation to php.

}

 

After the top configuration, reboot or reload nginx can.

 

(3) summary

Many web hosting can be written in the same configuration file, but this in later maintenance it will be very inconvenient (author fully understood, especially in the access of others through the maintenance of the platform). Try to write a few configuration files, so it looks short, easy to read.

 


Guess you like

Origin blog.51cto.com/4856198/2443140