CentOS6.4 install Nginx
Nginx is a high-performance reverse proxy server that supports Server Load balancer configuration, which is easy to use and easy to configure. In addition, Nginx can be easily expanded through modules, so Nginx has a large set of functions. You can refer to the official documentation or related materials.
Next, we will install and configure Nginx on CentOS 6.4.
Install Nginx
First, download the Nginx signature file:
1wgethttp://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpmImport the Nginx signature file and run the following command:
1sudorpm --importnginx_signing.keyThen, you can run the following command:
1sudoyuminstallnginxDuring installation, you may be prompted to install some dependent software packages.
After the installation is complete, the basic information of some directories and files is as follows:
- The process ID file is/var/run/nginx. pid.
- The Nginx configuration file is stored in the/etc/nginx/directory.
- The executable program file is/usr/sbin/nginx.
- The default site directory is/usr/share/nginx/html.
- The error log Path is/var/log/nginx/error. log/li>.
- The access log path is/var/log/nginx/access. log.
Verify Installation
View Nginx help information:
1sudo/usr/sbin/nginx -hTest whether the current Nginx default configuration file/etc/nginx. conf is available. Run the following command:
1sudo/usr/sbin/nginx -tStart the service
If you use the default configuration file/etc/nginx. conf to start Nginx, run the following command:
1sudo/usr/sbin/nginxIf you specify a configuration file, such as/home/shirdrn/servers/nginx/conf/nginx. conf, run the following command:
1sudo/usr/sbin/nginx -c /home/shirdrn/servers/nginx/conf/nginx.confAfter successful startup, You can query the Nginx process:
1ps-ef |grepnginxIf you have modified the configuration file and need to reload it, You can execute the following command:
1sudo/usr/sbin/nginx -s reloadTerminate Service
Terminate the Nginx service in two modes:
One is to force stop the service immediately and execute the following command:
1sudo/usr/sbin/nginx -s stopAnother method is to stop receiving new requests and wait for the processed requests to complete. Execute the following command:
1sudo/usr/sbin/nginx -s quitConfiguration example
The following is a simple configuration example for implementing Server Load balancer. The nginx. conf configuration is as follows:
01user nginx;02worker_processes 1;0304error_log /var/log/nginx/error.log warn;05pid /var/run/nginx.pid;060708events {09worker_connections 1024;10}111213http {14include /etc/nginx/mime.types;15default_type application/octet-stream;1617log_format main '$remote_addr - $remote_user [$time_local] "$request" '18'$status $body_bytes_sent "$http_referer" '19'"$http_user_agent" "$http_x_forwarded_for"';2021access_log /var/log/nginx/access.log main;2223sendfile on;24#tcp_nopush on;2526keepalive_timeout 65;2728#gzip on;2930upstream master {31server slave1:8888 weight=1;32server slave4:8888 weight=1;33server slave6:8888 weight=1;34}3536server {37listen 80;38server_name master;39location / {40root /usr/share/nginx/html/solr-cloud;41index index.html index.htm;42proxy_passhttp://master;43include /home/hadoop/servers/nginx/conf/proxy.conf44}45}4647}The configuration content of the/home/hadoop/servers/nginx/conf/proxy. conf file referenced above is as follows:
01proxy_redirect off;02proxy_set_header Host $host;03proxy_set_header X-Real-IP $remote_addr;04proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;05client_max_body_size 10m;06client_body_buffer_size 128k;07proxy_connect_timeout 300;08proxy_send_timeout 300;09proxy_read_timeout 300;10proxy_buffer_size 4k;11proxy_buffers 4 32k;12proxy_busy_buffers_size 64k;13proxy_temp_file_write_size 64k;When starting, specify the configuration file. For example, run the following command to start the Nginx service:
1sudo/usr/sbin/nginx -c /home/shirdrn/servers/nginx/conf/nginx.confBy accessing a link similar to the following, you can use Nginx for load balancing and distribute requests to the three configured servers (slave1, slave2, and slave3:
1Http: // master/solr-cloud/mycollection/select? Q = Shanghai & fl = * & fq = building_type: 1 & facet = true & facet. field = category & start = 0 & rows = 10Reference
- Http://nginx.org/en/linux_packages.html
- Http://nginx.org/en/docs/beginners_guide.html