Install nginx on centos 6.4 Server

Source: Internet
Author: User
1. Prepare the environment Yum-y install GCC gcc-C ++ Autoconf automake makeyum-y install zlib-devel OpenSSL -- devel PCRE-devel Yum install nginx 2. Download nginx Wget  Http://nginx.org/download/nginx-1.2.1.tar.gz     Tar-xzvf nginx-1.2.1.tar.gzcd nginx-1.0.2./configure -- sbin-Path =/root/soft/nginx Configure supports the following options:

-- Prefix = <path>-nginx installation path. If not specified, the default value is/usr/local/nginx.

-- Sbin-Path = <path>-nginx Executable File Installation path. It can only be specified during installation. If it is not specified, the default value is <prefix>/sbin/nginx.

-- Conf-Path = <path>-the default nginx. conf path without the-C option. If not specified, the default value is <prefix>/CONF/nginx. conf.

-- PID-Path = <path>-if no PID command is specified in nginx. conf, the default nginx. PID path is used. If not specified, the default value is <prefix>/logs/nginx. PID.

-- Lock-Path = <path>-nginx. Lock file path.

-- Error-log-Path = <path>-default error log path when no error_log command is specified in nginx. conf. If not specified, the default value is <prefix>/logs/error. log.

-- Http-log-Path = <path>-the default access log path when no access_log command is specified in nginx. conf. If not specified, the default value is <prefix>/logs/access. log.

-- User = <user>-the default nginx user if no USER command is specified in nginx. conf. If not specified, the default value is nobody.

-- Group = <group>-the default group used by nginx when no USER command is specified in nginx. conf. If not specified, the default value is nobody.

-- Builddir = Dir-specify the compiled directory

-- With-rtsig_module-enables the rtsig Module

3. Final Installation Make & make install   Let's test whether nginx works normally. Because we have installed the nginx binary execution file configuration in/usr/local/sbin/nginx (the preceding configure parameter -- sbin-Path =/usr/local/sbin/nginx ), directory/usr/local/sbin/is in the path environment variable of Linux by default, so we can omit the path to execute it: [root @ fsvps nginx-1.2.1] # nginx it will not display any information. Open your browser and access your nginx site through an IP address. If you see such a line of big black, nginx is working: Welcome to nginx! It looks very simple, just because there is no beautiful page for it. Let's simply configure its running configuration. The Configure parameter -- conf-Path =/usr/local/CONF/nginx. conf is its configuration file. Let's see. [Root @ fsvps nginx-1.2.1] # cd/usr/local/CONF/nginx/[root @ fsvps nginx] # lsfastcgi. conf fastcgi_params.default mime. types nginx. conf. default uwsgi_paramsfastcgi.conf.default Koi-UTF mime. types. default scgi_params uwsgi_params.defaultfastcgi_params Koi-win nginx. conf scgi_params.default win-UTF if there is no nginx. conf, but nginx. conf. default, we use it to copy a copy of nginx. conf (no nginx by default in earlier versions. conf) open it with a familiar Editor, VI nginx. conf finds the following part, which is about 35 rows, server {Listen 80Default ; SERVER_NAME localhost; Root/var/www/html/Default ; # Charset koi8-r; # access_log logs/host. Access. Log main; Location /{ # Root HTML; index index.html index.htm ;}....................} make three changes to the above red bold display part: Insert "Space default" after listen 80 and add a line of root/var/www/html/default to it; comment out root HTML; server {...} above a row {....} is to define a virtual host. The line we just added is to define the web directory of this fake host. The default value of the listen row indicates the server {...} the node is the default false host (default site). Run nginx-t to test whether the nginx configuration file has a syntax error: [root @ fsvps nginx] # nginx-tnginx: the configuration file/usr/local/CONF/nginx. conf syntax is oknginx: configuration file/usr/local/CONF/nginx. conf test is successful: no error is displayed, and the check is successful. If this is not the case, check whether your configuration file is wrong. Note that the end of the line must contain a semicolon. Create this directory on the hard disk: [root @ fsvps nginx] # mkdir-P/var/www/html/defaultwrite an HTML file index.html to the/var/www/html/default directory, use the editor you are familiar with to write whatever content and how to typeset it. Then let nginx reload the configuration file to see how the HTML page was created. Common error faq1) If you still see welcome to nginx during normal access! Please return and check the key points: Are there any index.html files in the/var/www/html/default directory? Check the file permission. Does the other user have the read permission? If you do not understand Linux File permissions, run chmod 755/var/www/html/default/index.html to check nginx. in the conf configuration file, only one server {...} is allowed {...} node, and whether there is listen 80 default in the node; a row, note that there must be default. Check whether there is a row of root/var/www/html/default in the above server {...} node. Check whether the path is correctly spelled. Check whether the # Root HTML; line in the location/{...} node is commented out. 2) If 404 not found or "this page cannot be found" is displayed, check the preceding location /{...} whether this row of index index.html index.htm is in the node; 3) if the access result shows an error such as "unable to find the server" or "unable to connect to the server": Run and check that the nginx process is running, run the PS aux | grep nginx command. Normally, there are three: nginx: Master process nginxnginx: worker processgrep nginx. If there are only three nginx entries, run nginx to re-enable nginx, if any error is reported, check according to instructions. Generally, the syntax of the configuration file is incorrect. Run nginx-t to check whether the configuration file has syntax errors. [Tips] # Root HTML in the location/{...} node. A line can be left empty: Put your created index.html in the/var/www/html/default/html directory. So far, our nginx can work normally.  View nginx Processes PS-Ef | grep nginx     4. Set to system boot service:
Create an nginx file in the/etc/init. d/directory as follows:

 

#! /Bin/bash # Nginx STARTUP script for the nginx HTTP Server # This script create it by gcec at 2009.10.22. # It is v.0.0.1 version. # If you find any errors on this scripts, please contact gcec cyz. # And send mail to support at gcec dot CC. # # Chkconfig:-85 15 # Description: nginx is a high-performance WEB and proxy server. # It has a lot of features, but it's not for everyone. # Processname: nginx # Pidfile:/var/run/nginx. PID # Config:/usr/local/nginx/CONF/nginx. conf   Nginxd=/APP/Nginx/Sbin/Nginx Nginx_config=/APP/Nginx/Conf/Nginx.Conf Nginx_pid=/Var/Run/Nginx.PID   Retval=0 Prog="Nginx"   # Source function library. ./Etc/rc. d/init. d/functions   # Source networking configuration. ./Etc/sysconfig/Network   # Check that networking is up. [$ {Networking} = "no"] & Exit 0   [-X $ nginxd]|Exit0     # Start nginx daemons functions. Start (){   If[-E $ nginx_pid];Then Echo"Nginx already running ...." Exit1 Fi   Echo-N $"Starting $ prog :" Daemon $ nginxd-C ${Nginx_config} Retval=$? Echo [$ Retval=0]&&Touch/VaR/Lock/Subsys/Nginx Return$ Retval   }     # Stop nginx daemons functions. Stop (){ Echo-N $ "Stopping $ prog :" Killproc $ nginxd Retval =$? Echo [$ Retval = 0] & Rm-F/var/lock/subsys/nginx/var/run/nginx. PID }     # Reload nginx service functions. Reload (){   Echo-N $"Reloading $ prog :" # Kill-HUP 'cat $ {nginx_pid }' Killproc $ nginxd-Hup Retval =$? Echo   }   # See how we were called. Case "$1" in Start) Start ;;   Stop) Stop ;;   Reload) Reload ;;   Restart) Stop Start ;;   Status) Status $ prog Retval=$? ;; *) Echo $"Usage: $ prog {START | stop | restart | reload | status | help }" Exit1 Esac   Exit$ Retval Chkco
Related Article

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.