Nginx installation and simple configuration

Source: Internet
Author: User

Nginx installation and simple configuration
Nginx installation 1. Download related componentsYum install-y gcc-c ++ # install the C/C ++ CompilerYum-y install gd-devel geoip-devel perl-ExtUtils-EmbedWget http: // 125.39.35.htm/files/40450000042A3380/zlib.net/zlib-1.2.8.tar.gzWget http://sourceforge.net/projects/pcre/files/pcre/8.37/pcre-8.37.tar.gzWget https://www.openssl.org/source/openssl-1.0.2h.tar.gzWget http://labs.frickle.com/files/ngx_cache_purge-2.1.tar.gzWget http://nginx.org/download/nginx-1.6.2.tar.gz 2. decompress and install zlib/pcre/openssl/nginxZlib/pcre these library files directly./configure & make install

tar xf openssl-1.0.2h.tar.gz -C /root
cd /root/openssl-1.0.2h
./config --prefix=/usr/local --openssldir=/usr/local/openssl
make
make install

 

 

 

 

Cd/root/nginx-1.6.2./configure --add-module=/root/ngx_cache_purge-2.1 --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-file-aio --with-ipv6 --with-http_spdy_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'-- With-http_degradation_module -- with-http_perl_module -- with-ld-opt =-Wl,-E -- with-mail_ssl_module -- with-http_image_filter_module -- with-http_geoip_module--with-http_ssl_module --with-openssl=/root/openssl-1.0.2h
makemake install
    

 

 

 

 

 

 

Error message: /usr/local/nginx/sbin/nginx: error  while loading shared libraries: libpcre.so. 1 : cannot open shared object file: No such file or directory Solution: cd /lib64 ln -s libpcre.so. 0.0 . libpcre.so. 1Start method: Start: nginx stop: nginx-s stop heavy load: nginx reload 3. Virtual Host Based on Domain Name: server {
Listen 80;
Server_name www1.zyg.com;
Root/etc/nginx/www1; # create a directory
Index index.html;
}
Server {
Listen 80;
Server_name www2.zyg.com;
Root/etc/nginx/www2;
Index index.html;
} IP-based VM: server {
Listen 192.168.122.11: 80;
Root/etc/nginx/www1;
Index index.html;
}
Server {
Listen 2.2.2.1: 80;
Root/etc/nginx/www2;
Index index.html;
} Port-based VM: server {
Listen 8001;
Root/etc/nginx/www1;
Index index.html;
}
Server {
Listen 8002;
Root/etc/nginx/www2;
Index index.html;
} 4. Access Control server {
Listen 8001;
Root www1;
Index index.html;
Auth_basic "test"; # A prompt
Auth_basic_user_file/usr/local/nginx/passwd. db;
}

Server {
Listen 8002;
Root www2;
Index index.html;
Allow 192.168.122.0/24;
Deny all;
} [Root @ node1 nginx] # htpasswd-c/usr/local/nginx/passwd. db power # set a password for power 5. smooth upgrade • replace the old executable program with the new executable program. For compiled and installed Nginx, You can compile and install the new version to the nginx installation path of the old version. before replacement, it is best to back up the old executable program
• Send the following commands:
Kill USR2 <nginx master process Number of the old version>
• The Old Master process will rename its pid file. oldbin (for example,/usr/local/nginx/logs/nginx. pid. and then execute the new version of the nginx executable program, start the new main process and the new Working Process in turn.
• The nginx instances of the new and old versions run simultaneously to process input requests. to gradually stop an earlier version of nginx instance, you must send a WINCH signal to the old master process. Then, its working process will start to be closed with ease:
Kill WINCH <Nginx master process Number of the old version>
• After a period of time, the old worker process processes all connected requests and then exits. Only the new worker process processes the input requests.
• At this time, we can decide whether to use the new version or reply to the old version;
Kill HUP <old master process number>: Nginx starts the working process without reloading the configuration file;
Kill QUIT <new master process number>: Shut down other worker processes normally (woker process );
If an error is reported, the following command is used to shut down the old working process before closing the master process Number:
Kill TERM <new worker process number>: force quit worker process;
Kill <new master process number or old master process number>: if a new worker process cannot exit for some reason, it sends a kill signal to it.
After the new master process exits, the old master process will be removed. the oldbin prefix. pid file. In this way, everything will be restored before the upgrade. If the upgrade is successful and you want to keep the new server, you can send a QUIT signal to the old master process, leave the server to run. 6. log cutting mv/data1/logs/access. log/data1/logs/20160520.log
Kill-USR1 'cat/var/run/nginx. Pi' # in this way, you do not need to use ps to find the Nginx main process number.

If you want it to regularly cut logs every day, you can write a shell script and use crontab to regularly run logs every day.

#! /Bin/bash
# Define the path for storing Nginx log files
Logs_path = "/var/logs/nginx /"

Mkdir-p $ {logs_path} $ (date-d "yesterday" + "% Y")/$ (date-d "yesterday" + "% m ")/
Mv $ {logs_path} access. log $ {logs_path} $ (date-d "yesterday" + "% Y")/$ (date-d "yesterday" + "% m ") /access _ $ (date-d "yesterday" + "% Y % m % d "). log
Kill-USR1 'cat/var/run/nginx. Pi'

Configure crontab and enter crontab-e.
Input:
00 00 ***/bin/bash/usr/loca/webserver/nginx/sbin/cut_nginx_log.sh

For more Nginx tutorials, see the following:

Deployment of Nginx + MySQL + PHP in CentOS 6.2

Build a WEB server using Nginx

Build a Web server based on Linux6.3 + Nginx1.2 + PHP5 + MySQL5.5

Performance Tuning for Nginx in CentOS 6.3

Configure Nginx to load the ngx_pagespeed module in CentOS 6.3

Install and configure Nginx + Pcre + php-fpm in CentOS 6.4

Nginx installation and configuration instructions

Nginx log filtering using ngx_log_if does not record specific logs

Nginx details: click here
Nginx: click here

This article permanently updates the link address:

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.