About nginx and build a name-based virtual hosting

Today will come and tell you how to build nginx and name-based virtual hosting

Brief introduction

Nginx (engine x) is a high performance Web server and reverse proxy server is a IMAP / POP3 / SMTP server

Russian programmer Igor Sysoev in 2002,
Nginx Web server is the fastest growing market share reached 33.3%
global usage ranked second in 2011 established commercial companies

Nginx source code structure:

The code amount of about 11 million lines of C code
source code directory structure
core (backbone and basic settings)
Event (event-driven model and a different IO multiplexing module)
HTTP (HTTP server and modules)
mail (mail proxy server and modules)
os (operating RELATED implementation)
Misc (miscellaneous)

Nginx features:

Reverse proxy, load balancer
and high reliability, a single master multi-mode worker
highly scalable, highly modular
non-blocking
event-driven
low memory consumption
hot deployment

nginx application environment

Static file server
reverse proxy, load balancing,
security and defense
intelligent routing (enterprise-level grayscale test, map POI cut a key stream)
gray publish
static
message push
picture compression in real-time
anti-hotlinking

Common use of official modules

1gx_http_core_module

Support http protocol. Http segment usual configuration, server web hosting segment, location and other segments. Here are some of the module configuration syntax.

ngx_http_proxy_module

Using 'gzip' compression methods, help to reduce the size of the transmission data is the half or more. Providing request return speed.

2.3、ngx_http_proxy_module

This module allows forward the request to another server, implement the functions of the proxy server.

Common to achieve reverse proxy server.

ngx_http_rewrite_module

The means for using regular expressions pcre the URI change request, returning a redirected, or it is judged to select the corresponding configuration item.

ngx_http_upstream_module

The user module is distributed to the different server nodes. Supported by proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass, memcached_pass, grpc_pass such as server group.

Nginx catalog description

conf: directory of all profiles Nginx
configuration file fastcgi.conf fastcgi parameters of
fastcgi.conf.default fastcgi.conf the original backup
fastcgi_params fastcgi parameter file
mime.types media types
nginx.conf Nginx default main configuration file
scgi_params scgi related parameter file
uwsgi_params uwsgi related parameter files

fastcgi_temp: fastcgi temporary data directory
html: Compile the default installation directory site Nginx of
50x.html elegant alternative error pages display file
index.html default home page file, index.html, index.php, etc.
logs: Nginx default log path, including error log and access log
access.log Nginx default access log file tail -f access.log
error.log Nginx error log file, if the start failure, to view the file
after the pid file nginx.pid Nginx, Nginx process starts , ID number will be written this document all processes

proxy_temp: temporary directory
sbin: Nginx directory command
nginx Nginx start command nginx
scgi_temp: temporary directory
uwsgi_temp: temporary directory

nginx configuration parameters to explain

worker_processes 1; the number of worker processes
worker_connections 1024; each worker process supports the maximum number of connections
include mime.types; nginx supported media type library file
default_type application / octet-stream; the default media type
sendfile on; open and efficient transfer mode
keepalive_timeout 65; connection timeout
server represents a separate virtual host site
listen 80; ports provide services, default 80
server_name localhost; host domain name service delivery
location location blocks
root root directory of the site's html

Build Web Hosting

1 added usr / local / nginx / conf / nginx.conf in the configuration file (format)
Server {
the listen 80;
server_name www.nautilus.org;
LOCATION / {
the root HTML / WWW;
index index.html index.htm;
}
}

2 Create a directory usr / local / nginx / html Lane
3 into this newly created file input echo "xiaoxiaoxiao" >> index.html (see the need to enter the quotes)
4 Add the IP in its own virtual machine etc / hosts inside and the name of the virtual host
5 does not look nginx start if not started
6 into the usr / local / nginx / sbin restart files, -s reload command is ./nginx
7 input curl virtual host name to see if success
if you are on the 8 window View need to change the C: \ Windows \ System32 \ drivers \ etc in the hosts file (Notepad need to run in administrator mode)

Guess you like

Origin blog.51cto.com/14375700/2416273