Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Server \ CentOS 6.5 installation and simple configuration Nginx     - Configure the Linux kernel and use iptables to do port mapping (Linux)

- Taught you how to install Ubuntu Linux (Linux)

- 24 Docker recommendations (Linux)

- To install Google Chrome browser under Ubuntu 14.04 LTS (Linux)

- How to install Ubuntu strategy game Wesnoth 1.12.0 (Linux)

- LinSSID: a graphical Wi-Fi scanner under Linux (Linux)

- Intel Graphics Installer 1.0.3 released, support for Ubuntu (Linux)

- Ceph tuning --Journal and tcmalloc (Server)

- Installation salt-minion on RHEL5 (Linux)

- CentOS 7.0 Close firewall is enabled by default iptables firewall (Linux)

- CentOS 6.5 dual card configuration, one of the external network, a local area network connection (Linux)

- File easier to compare tools under Linux (Linux)

- Ubuntu Tutorial: E: Failed to get lock / var / lib / apt / lists / lock - open (Linux)

- 10 Best Swift Tutorial examples (Programming)

- 10 important Linux ps command combat (Linux)

- Learning and Practice (Linux)

- ORA-08102 errors (Database)

- Linux basic introductory tutorial ---- regex basis (Linux)

- How to configure a server in a MySQL Cluster (Database)

- Writing Better Bash build script 8 (Programming)

 
         
  CentOS 6.5 installation and simple configuration Nginx
     
  Add Date : 2016-05-29      
         
       
         
  CentOS 6.5 installation and simple configuration Nginx

First, Preparation

(1) because nginx need to access port 80 so turn off the firewall or open ports, and selinux.

Command Reference

Turn off the firewall:

[Root @ local ~] # iptables -I INPUT -p tcp --dport 80 -j ACCEPT

[Root @ local ~] # service iptables save

Close selinux:

[Root @ local ~] # setenforce 0

[Root @ local ~] # vim / etc / selinux / config

The SELINUX = enforcing to SELINUX = disabled
 

(2) If the domain name is used to build their own DNS service

Second, the installation

(1) needs to be installed to run because nginx pcre, zlib packages, etc., so we installed

Pcre = Pcre Compatible Regular Expressions

[Root @ local ~] yum -y install pcre * zlib * # or compile and install

[Root @ local ~] # useradd -M -s / sbin / nologin nginx # Create nginx service
 

Launching User

(3) compile and install nginx, download address: http: //nginx.org/en/download.html install the latest stable version of nginx-1.8.0

[Root @ local ~] # tar zxf nginx-1.8.0.tar.gz

[Root @ local ~] # cd nginx-1.8.0

[Root @ local nginx-1.8.0] # ls

auto CHANGES.ru configure html Makefile objs src

CHANGES conf contrib LICENSE man README

[Root @ local nginx-1.8.0] # ./configure --user = nginx --group = nginx --prefix = / application / nginx-1.8.0 --with-http_stub_status_module --with-http_ssl_module #. / Configure parameter Description -help

[Root @ local nginx-1.8.0] # make

[Root @ local nginx-1.8.0] # make install
 

(4) production of soft connection

[Root @ local nginx-1.8.0] #ln -a /application/nginx-1.8.0/

/ Application / nginx
 

(5) Basic Usage

# Syntax check

[Root @ local nginx-1.8.0] # / application / nginx / sbin / nginx -t

nginx: the configuration file /application/nginx-1.8.0/conf/nginx.conf syntax is ok

nginx: configuration file /application/nginx-1.8.0/conf/nginx.conf test is successful

# Start Service

[Root @ local nginx-1.8.0] # / application / nginx / sbin / nginx

# Port inspection

[Root @ local nginx-1.8.0] # netstat -lnt

# Inspection process

[Root @ local nginx-1.8.0] # ps -ef | grep nginx # port information is stored in

/ Application / nginx / logs / nginx.pid file

# View port occupied by process

[Root @ local nginx-1.8.0] # lsof -i: 80

# Error log

/application/nginx/logs/error.log
 

Third, write a script nginx service

In order to facilitate usage by server to start, close, open, reload nginx service so we have to compile

Write nginx service script (script I have written for informational purposes only!)

[Root @ local ~] # vim /etc/init.d/nginx

#! / Bin / bash

#chkconfig: - 99 20

#description: Nginx Server Contorl Script

PROG = "/ application / nginx / sbin / nginx"

PIDF = "/ application / nginx / logs / nginx.pid"

ok = `echo -e" \ e [1; 31m [ok] \ e [0m "`

no = `echo -e" \ e [1; 31m [no] \ e [0m "`

detection = `/ application / nginx / sbin / nginx -t 2> & 1`

screen_1 = `echo $ detection | awk '{print $ 6, $ 7, $ 8}'`

screen_2 = `echo $ detection | awk '{print $ 13, $ 14, $ 15}'`

if [ "$ screen_1" = "syntax is ok"] && [ "$ screen_2" = "test is successful"];

then

    case "$ 1" in

    start)

      $ PROG

      echo "Nginx Is starting state $ ok"

      ;;

    stop)

      kill -s QUIT $ (cat $ PIDF)

      echo "Nginx Is closing state $ ok"

      ;;

    restart)

      $ 0 stop

      $ 0 start

      echo "Nginx Is to restart state $ ok"

      ;;

    reload)

      kill -s HUP $ (cat $ PIDF)

      echo "Nginx Is overloaded state $ ok"

      ;;

    *)

      echo "Usage: $ 0 (start | stop | restart | reload)"

      exit 1

      esac

else

  echo "Nginx check state $ no"

  echo "Please check the configuration file"

  echo "$ detection"

fi

exit 0
 
  
[Root @ local ~] # chmod + x /etc/init.d/nginx

[Root @ local ~] # chkconfig -add nginx # add a system service

[Root @ local ~] # chkconfig nginx on
 

Fourth, simple nginx web site

Nginx default site directory is the installation html directory here (/ application / nginx / html)

In the main configuration file /application/nginx/conf/nginx.conf view, redeployed for web pages

Just / application / nginx / html / index.html in to replace

The main configuration file to explain

 

[Root @ local ~] # egrep -v "# | ^ $" /application/nginx/conf/nginx.conf

worker_processes 1; # specify the number of processes open Nginx

events {# set Nginx operating mode and on-line connections

worker_connections 1024;

}

http {

include mime.types; # main module commands implementation sets the configuration file that contains all files

default_type application / octet-stream; # http belong core module command, located here

Type set to binary, that is, when the file type is not defined in this way, for example, no PHP

Environment, nginx is not given to resolve, this time, to access a PHP file browser download window will appear.

sendfile on; # for efficient file transfer mode

keepalive_timeout 65; set the client request header file read timeout, if more than this

Between the server closes the connection.

Keyword server {# define virtual host begins

listen 80; # is used to specify the virtual host port services

Used to specify the ip address or domain, multiple domain names separated by spaces; server_name localhost

location / {

root html;

index index.html index.htm; # is used to set the default home page to access

}

error_page 500 502 503 504 /50x.html;# static pages redirect server error

Page, such as page Ctrip's website crashes occur

location = /50x.html {

root html;

}

}

}
     
         
       
         
  More:      
 
- ADSL router to defend their own network security methods (Linux)
- Hadoop2.0 configuration yarn success (Server)
- Ubuntu 14.10 Apache installation and configuration (Server)
- Linux raw socket (Programming)
- Secondary exponential smoothing prediction method implemented in Python (Programming)
- Java garbage collection and heap memory layout (Programming)
- Linux tar compressed exclude a folder (Linux)
- Ubuntu 14.04 LTS compiler installation R Source Code (Linux)
- Sniffer Linux Environment (Linux)
- Log4cplus logging facility configuration, installation, testing (Linux)
- Shell Common Command Summary (Programming)
- Do not find ifconfig eth0 and IP address under CentOS6.5 (Linux)
- Elaborate 10-point difference between the new and malloc (Programming)
- Linux Network Programming - raw socket Example: sending a UDP packet (Programming)
- The Linux disguised as windows to make the system more secure (Linux)
- Experience RHEL7 new features (Linux)
- systemd run levels and service management command Introduction (Linux)
- The basic method RHEL6 (CentOS6) used in the source package compiled RPM: Upgrade OpenSSH articles (Linux)
- Linux uses the SMTP proxy to send mail (Linux)
- Java collections series (Programming)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.