Nginx is a Russian developed by the HTTP server, a lot of features, this article mainly use it to provide Web services. Installation method is compiled and installed. The program version and system environment used in this article are as follows:
Operating system: centos6.6 x86_64
nginx:nginx-1.8.0
First, compile and install Nginx
The package group "development tools" and "Server Platform development" need to be installed first. Also, because URL rewriting is supported in the default compilation options, install Pcre-devel.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6D/DB/wKioL1VtvTzyylTYAAD88NEX3mA165.jpg "title=" 1.png " alt= "Wkiol1vtvtzyyltyaad88nex3ma165.jpg"/>
Groupadd-r nginxuseradd-g nginx-r nginx Add user, let Nginx worker process as Nginx user's identity run.
#./configure--prefix=/usr/local/nginx--conf-path=/etc/nginx/nginx.conf--user=nginx--error-log-path=/var/log/ Nginx/error.log--http-log-path=/var/log/nginx/access.log--pid-path=/var/run/nginx/nginx.pid--lock-path=/var/ Log/nginx.lock--with-http_ssl_module# make && make install
There are, of course, many options for compiling, to provide different features, to use the above compilation options, to allow Nginx to provide Web services, and to provide support for the HTTPS protocol, and many others remain to be learned.
/usr/local/nginx//sbin/nginx
After the installation is complete, you can start Nginx and use the browser test.
Second, the configuration file
Required configuration for normal operation
User
Pid
The configuration of the event{....}:event segment is globally valid, the configuration content can be empty, but the "event{}" configuration segment must exist.
Performance-related configurations
There are many performance-related configurations that need to be referenced in official documentation.
Configuration to use as a Web server
Put in the "HTTP {
} "in the configuration section, introduced by Ngx_http_core_module. This article focuses on HTTP-related configuration segments.
Use the following configuration to enable the host to provide HTTP services and familiarize yourself with the use of "location" "Log" "Access control" and so on.
User nginx;worker_processes 1;events { worker_connections 1024;} http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name www.a.com; location = /index.html { root "/web/images"; index index.html; } location /images { root " /web/images "; index index.html; } location / { root "/web/a"; } location ~* \. (txt|text) $ { root "/web/txt"; } error_page 404 =5050 /error.html; location /sta { root "/web"; index index.html; auth_basic "Nginx info"; auth_basic_user_file "/usr/local/ NGINX/.HTPASSWD "; allow 172.16.0.0/16; deny all; access_log /usr/local/nginx/access.log; error_log /usr/local/nginx/error.log; } }}
If you want to configure Nginx support to use HTTPS, you need to configure the following
server { listen 443 ssl; server_name www.b.com; ssl_certificate /etc/nginx/ ssl/nginx.crt; #存放CA颁发的证书 ssl_certificate_key /etc/nginx/ssl/nginx.key; #存放私钥 ssl_session_ Cache shared:ssl:1m; ssl_session_timeout 5m; ssl_ciphers high:!anull:! md5; ssl_prefer_server_ciphers on; location / { root /vhosts/web1; index index.html index.htm; } }
Using Nginx to provide Web services