Installing Nginx and Nginx tuning under Linux

Source: Internet
Author: User

Linux system for the Rhel5.6,nginx version of nginx-1.1.6.tar.gz, you can download the latest installation on the Internet, because Nginx is based on a number of modules to achieve a powerful function, so to install and compile other module packages, the module package installed here are: Agentzh-encrypt Ed-session-nginx-module-v0.02-0-gc752861.tar.gz, chunkin-nginx-module-0.23rc2.tar.gz, Google-perftools-1.8.3.tar.gz, libunwind-0.99.tar.gz, pcre-8.11.tar.gz, Simpl-ngx_devel_ Kit-v0.2.17-10-g4192ba6.tar.gz, if necessary, you can download more packages to compile and install, you can download the necessary software and documents in wiki.nginx.org. Install Nginx to start from the installation of each module package, the installation of each module package is not in order to limit, of course, before starting to install these packages to first install GCC, gcc-c++ and other tools, first ensure that the system's 80 port is not occupied and other previous work.

Operation Process:

[email protected] ~]# Yum install gcc gcc-c++ openssl-devel-y # # #准备工作

[[email protected] ~]# mkdir nginx # # #将nginx模块包放在这个目录中

[Email protected] nginx]# tar zxf agentzh-encrypted-session-nginx-module-v0.02-0-gc752861.tar.gz

[[Email protected] nginx]# mv Agentzh-encrypted-session-nginx-module-c752861/encrypted-session-nginx-module # # # The module can only decompress, do not need to compile the installation, you need to compile nginx when you add it in

[Email protected] nginx]# tar zxf chunkin-nginx-module-0.23rc2.tar.gz

[[Email protected] nginx]# mv Chunkin-nginx-module-0.23rc2 Chunkin-nginx-module # # #该模块仅解压即可, do not need to compile the installation, need to compile nginx when you add it in

[Email protected] nginx]# tar zxf google-perftools-1.8.3.tar.gz

[[Email protected] nginx]# mv google-perftools-1.8.3 Google-perftools # # #该模块仅解压即可, do not need to compile the installation, need to compile nginx when you add it in

[Email protected] nginx]# CD Google-perftools

[[email protected] google-perftools]#./configure --enable-frame-pointers # # # # # # If it is a 64-bit system to add--enable-frame-pointers parameters

[[email protected] google-perftools]# make &&make install # # #该模块编译安装后还要在nginx编译时将其添加进去

[Email protected] nginx]# tar zxf libunwind-0.99.tar.gz

[Email protected] nginx]# MV libunwind-0.99 Libunwind

[Email protected] nginx]# CD Libunwind

[Email protected] libunwind]#/configure cflags=-fpic

[email protected] libunwind]# make Cflags=-fpic

[[email protected] libunwind]# make install Cflags=-fpic # # # #该模块编译安装要加CFLAGS =-fpic

[Email protected] nginx]# tar zxf pcre-8.11.tar.gz

[Email protected] nginx]# CD pcre-8.11

[Email protected] pcre-8.11]#./configure

[[email protected] pcre-8.11]# make

[[email protected] pcre-8.11]# make install # # # #安装nginx需要的正则表达式包, the software function is nginx rewrite function need it

[Email protected] nginx]# tar zxf simpl-ngx_devel_kit-v0.2.17-10-g4192ba6.tar.gz

[[Email protected] nginx]# MV Simpl-ngx_devel_kit-4192ba6/simpl-ngx_devel_kit # # #该模块仅解压即可, do not need to compile the installation, need to compile nginx when you add it in

[Email protected] nginx]# ln-s/usr/local/lib/libprofiler.so.0/lib/

[Email protected] nginx]# ln-s/usr/local/lib/libprofiler.so.0/usr/lib/

[Email protected] nginx]# ln-s/usr/local/lib/libunwind.so.7/lib/

[[email protected] nginx]# ln-s/usr/local/lib/libunwind.so.7/usr/lib/# # # #这4步的软链接需要做, I here is a 32-bit system, if it is a 64-bit system, you can do the following steps:

[email protected] nginx]# ln-s/usr/local/lib/libprofiler.so.0/lib/

[Email protected] nginx]# ln-s/usr/local/lib/libprofiler.so.0/usr/lib/

[Email protected] nginx]# ln-s/usr/local/lib/libprofiler.so.0/lib64/

[Email protected] nginx]# ln-s/usr/local/lib/libprofiler.so.0/usr/lib64/

[Email protected] nginx]# ln-s/usr/local/lib/libunwind.so.7/lib/

[Email protected] nginx]# ln-s/usr/local/lib/libunwind.so.7/usr/lib/

[Email protected] nginx]# ln-s/usr/local/lib/libunwind.so.7/lib64/

[Email protected] nginx]# ln-s/usr/local/lib/libunwind.so.7/usr/lib64/

[Email protected] nginx]# tar zxf nginx-1.1.6.tar.gz

[Email protected] nginx]# CD nginx-1.1.6

[Email protected] nginx-1.1.6]# /configure--prefix=/usr/local/nginx--user=www--group=www--with-http_ssl_ Module--with-file-aio--with-http_stub_status_module--with-http_sub_module--with-http_addition_module-- With-http_random_index_module--with-http_secure_link_module--with-http_dav_module--with-http_mp4_module-- With-http_degradation_module--with-http_gzip_static_module--with-google_perftools_module--with-http_flv_module --add-module=/root/nginx/chunkin-nginx-module--add-module=/root/nginx/simpl-ngx_devel_kit--add-module=/root/ Nginx/encrypted-session-nginx-module # # #将上面解压或者安装好的各模块软件添加进去

[[email protected] nginx-1.1.6]# make

[[email protected] nginx-1.1.6]# make install

[Email protected] nginx]# useradd-m www # # #创建不带用户目录www用户

[Email protected] nginx]#/usr/local/nginx/sbin/nginx # # # #启动nginx服务

[[email protected] ~]# ps-ef |grep nginx # # # #如果配置文件中的 User Nobody did not cross out the comments, the worker process user here will be nobody, remove the comments will become nobody

Root 3324 1 0 10:18? 00:00:00 Nginx:master Process/usr/local/nginx/sbin/nginx

Nobody 3325 3324 0 10:18? 00:00:00 Nginx:worker Process

Nobody 3326 3324 0 10:18? 00:00:00 Nginx:worker Process

Nobody 3327 3324 0 10:18? 00:00:00 Nginx:worker Process

Nobody 3328 3324 0 10:18? 00:00:00 Nginx:worker Process

Root 4035 12365 0 10:50 pts/3 00:00:00 grep nginx

[[email protected] ~]# cat/usr/local/nginx/logs/nginx.pid # # # #这两步都发现有nginx服务进程, stating that Nginx started successfully

3324

Come here, Nginx installation is complete and can run normally, the following to Nginx optimization, here to nginx configuration file parameter optimization, the original configuration file of Nginx Backup to Nginx.conf_bak, the following is the optimized configuration file:

[Email protected] ~]# MV nginx_laoshi.conf/usr/local/nginx/conf/nginx.conf

[Email protected] ~]# cat/usr/local/nginx/conf/nginx.conf

User nobody;

Worker_processes 4;

Worker_cpu_affinity 00000001 00000010 00000100 00001000


Error_log Logs/error.log error;

PID Logs/nginx.pid;


Events {

Worker_connections 102400;

use Epoll;

}


HTTP {

Include Mime.types;

Default_type Application/octet-stream;


Log_format Main ' $remote _addr-$remote _user [$time _local] "$request" '

' $status $body _bytes_sent ' $http _referer '

' "$http _user_agent" "$http _x_forwarded_for";

Access_log Logs/access.log Main;

Client_header_buffer_size 4k;

Large_client_header_buffer 4 32k;

Open_file_cache max=102400 inactive=20s;

open_file_cache_valid 30s;

open_file_cache_min_uses 1;

#client_max_body_size 8m;

server_names_hash_bucket_size 128;

Sendfile on;

#autoindex on;

Tcp_nopush on;

tcp_nodelay on;

Keepalive_timeout 120;


gzip on;

gzip_static on;

Gzip_min_length 1k;

Gzip_buffer 4 16k;

gzip_types text/css text/javascript application/xml text/plain application/x-javascript;

gzip_vary on;

Gzip_comp_level 5;

upstream www.vfast.com.cn {

#ip_hash;

#fair;

#url_hash;

server 10.255.254.132:80 max_fails=5;

server 10.255.254.134:80 weight=10;

}

server {

Listen 80;

server_name www.vfast.com.cn;

Location/{

Proxy_pass http://www.vfast.com.cn;

}

}

Server {

Listen8080;

server_name stats.vfast.com.cn;

Location/status {

stub_status on;

Access_log off;

auth_basic "status";

}

}

}

Here the configuration file parameter tuning is for a machine to do, different machine parameter tuning is slightly different, should be done according to the actual situation, after tuning completed, to restart Nginx service:

[[email protected] ~]#/usr/local/nginx/sbin/nginx-s Reload # # # # #nginx服务平滑的重启, or you can also do the following to achieve the Nginx smooth restart:

[[email protected] ~]# ps-ef |grep nginx |grep master |awk ' {print $} ' # # #只查找nginx主进程号

3324

[Email protected] ~]# kill-hup 3324 # # #nginx实现了平滑重启

OK, here, Nginx compiled installation and tuning is complete.


This article from "Personal Feelings" blog, declined reprint!

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.