Install Nginx in Centos (1) simple installation

Source: Internet
Author: User
Tags sendfile nginx server
Pre-installation: simple installation and post-Installation Considerations: 1. Nginx's Disaster Recovery Cluster Server Load balancer should be considered; 2. health check is not performed on web nodes; 1. Environment preparation: Centos5.4Nginx1.2.1: wgetwww.nginx.orgdownloadnginx-1.2.1.tar.gz 2: Installation Steps # Install gcc compiler and related

Preliminary installation: first, simple installation. Later, you need to consider the following: 1, to consider Nginx own disaster recovery/cluster/load balancing 2, no health check on the web Node 1, Environment preparation Centos 5.4 Nginx 1.2.1: wget http://www.nginx.org/download/nginx-1.2.1.tar.gz 2: installation Steps # Install the gcc compiler and related

Early StageInstall:
FirstSimpleInstall
Later considerations:
1. Consider Nginx's own disaster recovery/cluster/Server Load balancer
2. No health check is performed on the web node.

1. Prepare the environment
Centos 1, 5.4
Nginx 1.2.1: wget http://www.nginx.org/download/nginx-1.2.1.tar.gz

2:InstallProcedure
#InstallGcc compiler and related tools yum-y install gcc-c ++ autoconf automake make
#InstallRelated modules yum-y install zlib-devel openssl -- devel pcre-devel


# Cd/usr/local/src
# Wget http://www.nginx.org/download/nginx-1.2.1.tar.gz
# Tar-zxvf nginx-1.2.1.tar.gz // extract package

#./Configure -- prefix =/usr/local/nginx // compile the source code.Install
# Make
# Make install

Configuration File: (configuration and annotation collection and Network)
#/Usr/local/nginx/conf/nginx. config
----------------------------------------- Nginx. config ----------------------------------------------------------------
# Running user
# User nobody;
# Start the process. Generally, it is set to be equal to the number of CPUs
Worker_processes 1;

# Global error logs and PID files
Error_log/var/log/nginx/error. log;
Pid/var/run/nginx. pid;

# Working mode and maximum number of connections
Events {
Use epoll; # epoll is a method of Multiplexing IO (I/O Multiplexing), but it is only used for Linux and later kernels, which can greatly improve nginx performance.
Worker_connections 1024; # maximum number of concurrent connections of a single backend worker process
# Multi_accept on;
}

Http {
# Set the mime type, which is defined by the mime. type file.
Include/etc/nginx/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 "';

# Set the log format
Access_log/var/log/nginx/access. log main

# The sendfile command specifies whether nginx calls the sendfile function (zero copy mode) to output files. For common applications,
# It must be set to on. If it is used for downloading and other application disk I/O heavy load applications, you can set it to off to balance the disk and network I/O processing speed and reduce the system uptime.
Sendfile on;
# Tcp_nopush on;

# Connection timeout
# Keepalive_timeout 0;
Keepalive_timeout 65;
Tcp_nodelay on;

# Enable gzip Compression
Gzip on;
Gzip_disable "MSIE [1-6] \. (?!. * SV1 )";

}

Server {
# Listening to port 80
Listen 80;
# Define access using www.xx.com
Server_name www.xx.com;

# Set access logs for the current virtual host
Access_log logs/www.xx.com. access. log main;

# Default request
Location /{
Root/usr/local/nginx/html; # define the default website root directory location of the server
Index. php index.html index.htm; # define the name of the home index file

}

# Define error prompt page
Error_page 500 502 503 x.html;
Location =/50x.html {
Root/usr/local/nginx/html;
}

Certificate ------------------------------------------------------------------------------------------------------------------------------------


3. How to start Nginx
# Start nginx
#./Usr/local/nginx/sbin/nginx-t
The following information is displayed as correct

the configuration file /usr/local/nginx/conf/nginx.conf syntax is okconfiguration file /usr/local/nginx/conf/nginx.conf test is successful


After the nginx process is started successfully, check the nginx process information: # ps-ef | grep nginx and check whether the nginx process exists to check whether the nginx process has been started successfully.


# Restart nginx
#./Usr/local/nginx/sbin/nginx-s reload

Test http://www.xx.com/
Check the centos firewall settings and whether the corresponding port is enabled. You can use the setup command to Set firewall, dns, network, and other information.
If no changes are made to the default configuration file, you can directly access the nginx server using a browser. The following message is displayed: Welcome to Nginx.

4. Optimization
Vim/etc/sysctl. conf
Add at the end (to be studied in detail)
Net. ipv4.tcp _ max_syn_backlog = 65536
Net. core. netdev_max_backlog = 32768
Net. core. somaxconn = 32768
Net. core. wmem_default = 8388608
Net. core. rmem_default = 8388608
Net. core. rmem_max = 16777216
Net. core. wmem_max = 16777216
Net. ipv4.tcp _ timestamps = 0
Net. ipv4.tcp _ synack_retries = 2
Net. ipv4.tcp _ syn_retries = 2
Net. ipv4.tcp _ tw_recycle = 1
Net. ipv4.tcp _ tw_reuse = 1
Net. ipv4.tcp _ mem = 94500000 915000000 927000000
Net. ipv4.tcp _ max_orphans = 3276800
Net. ipv4.ip _ local_port_range = 1024 65535


Save and exit.

Sysctl-p






2

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.