Linux source installation nginx and configuration

Source: Internet
Author: User
Tags prepare

Linux compiler install Nginx, configure self-startup script

This article to the students to introduce a Linux compiler installation Nginx, configure the Self-startup script tutorial, I hope you need to know a friend can learn to learn OH.

In the company's SuSE server install Nginx, recording the installation process:

Refer to this article: Linux compiles and installs Nginx from the source code:

1.1. Prepare Pcre Library
Pere is designed to allow Nginx to support regular expressions. Just prepared, not installed, to avoid errors in 64-bit systems.

The code is as follows Copy Code

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.11.tar.gz

TAR-ZXF pcre-8.11.tar.gz

1.3. Prepare Zlib Library
It is also only prepared, not installed, to avoid errors in 64-bit systems.

The code is as follows Copy Code

wget http://zlib.net/zlib-1.2.5.tar.gz
TAR-ZXF zlib-1.2.5.tar.gz

2.1. Download, create temp directory

The code is as follows Copy Code

wget http://nginx.org/download/nginx-1.5.5.tar.gz//In the company is downloaded to local and then rz-by uploaded to the server
TAR-ZXF nginx-1.5.5.tar.gz
CD nginx-1.5.5
Mkdir-p/var/tmp/nginx

2.2. Compiling and installing

Detailed compilation configuration options See "nginx compilation parameter Resolution"

copy code

root64:~ #./configure--prefix=/usr/local/nginx--pid-path=/var/run/nginx.pid--lock-path=/var/lock/ Nginx.lock--with-http_dav_module--with-http_flv_module--with-http_realip_module--with-http_gzip_static_module- -with-http_stub_status_module--with-mail --with-pcre=. /pcre-8.11--with-zlib=. /zlib-1.2.5--with-debug--http-client-body-temp-path=/var/tmp/nginx/client--http-proxy-temp-path=/var/tmp/nginx /proxy--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi-- http-scgi-temp-path=/var/tmp/nginx/scgi 
root64:~ # make && make install
root64:~ # ln-s/usr/local /nginx/sbin/nginx/usr/sbin/


--prefix #nginx安装目录, default in/usr/local/nginx
--pid-path #pid问件位置, default in Logs directory
--lock-path #lock问件位置, default in Logs directory
--with-http_ssl_module #开启HTTP the SSL module to support HTTPS requests.
--with-http_dav_module #开启WebDAV扩展动作模块, you can specify permissions for files and directories
--with-http_flv_module #支持对FLV文件的拖动播放
--with-http_realip_module #支持显示真实来源IP地址
--with-http_gzip_static_module #预压缩文件传前检查 to prevent files from being repeatedly compressed
--with-http_stub_status_module #取得一些nginx的运行状态
--with-mail #允许POP3/IMAP4/SMTP Agent Module
--with-mail_ssl_module #允许POP3/IMAP/SMTP can use SSL/TLS
--with-pcre=. /pcre-8.11 #注意是未安装的pcre路径
--with-zlib=. /zlib-1.2.5 #注意是未安装的zlib路径
--with-debug #允许调试日志
--http-client-body-temp-path #客户端请求临时文件路径
--http-proxy-temp-path #设置http Proxy Temp file path
--http-fastcgi-temp-path #设置http fastcgi Temporary file path
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi #设置uwsgi Temporary file path
--http-scgi-temp-path=/var/tmp/nginx/scgi #设置scgi Temporary file path

2.3, boot from the Nginx script

The code is as follows Copy Code

/etc/init.d/nginx
#! /bin/bash
# Description:startup script for webserver on CentOS. CP It IN/ETC/INIT.D and
# chkconfig--add nginx && chkconfig nginx on
# then you can use Server command control Nginx
#
# chkconfig:2345 08 99
# Description:starts, stops Nginx

Set-e
Path= $PATH:/usr/local/nginx/sbin/
desc= "Nginx Daemon"
Name=nginx
daemon=/usr/local/nginx/sbin/$NAME
Configfile=/usr/local/nginx/conf/nginx.conf
Pidfile=/var/run/nginx.pid
Scriptname=/etc/init.d/$NAME

# Gracefully Exit If the package has been removed.
Test-x $DAEMON | | Exit 0

D_start () {
$DAEMON-C $CONFIGFILE | | Echo-n "Already Running"
}

D_stop () {
Kill-quit ' Cat $PIDFILE ' | | Echo-n "Not Running"
}

D_reload () {
Kill-hup ' Cat $PIDFILE ' | | Echo-n "can ' t reload"
}

Case "$" in
Start
Echo-n "Starting $DESC: $NAME"
D_start
echo "."
;;
Stop
Echo-n "Stopping $DESC: $NAME"
D_stop
echo "."
;;
Reload
Echo-n "Reloading $DESC configuration ..."
D_reload
echo "Reloaded."
;;
Restart
Echo-n "Restarting $DESC: $NAME"
D_stop
Sleep 1
D_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
Exit 3
;;
Esac
Exit 0

Add Nginx to the self-starting service and start:

The code is as follows Copy Code

chmod 700/etc/init.d/nginx
Chkconfig--add Nginx
Chkconfig--level 2345 Nginx on
/etc/init.d/nginx start

Re-configure automatic daily-cut nginx log script:

The code is as follows Copy Code

vi/usr/local/nginx/sbin/cut_nginx_log.sh

#!/bin/bash
# This script run at 00:00
# The Nginx logs path
Logs_path= "/usr/local/nginx/logs/"
Logs_bak_path= "/data/logs/nginx/"

Mkdir-p ${logs_bak_path}$ (date-d "Yesterday" + "%Y")/$ (date-d "Yesterday" + "%m")/
CP ${logs_path}access.log ${logs_bak_path}$ (date-d "Yesterday" + "%Y")/$ (date-d "Yesterday" + "%m")/access_$ (date-d " Yesterday "+"%y%m%d "). Log
RM-RF ${logs_path}*.log
KILL-USR1 ' Cat/var/run/nginx.pid '

Installation Complete:)

Nginx Configuration parameters:

User Www-data; # #定义运行nginx的用户

Worker_processes 4; # #nginx进程数, set a value equal to the number of system CPUs

Worker_rlimit_nofile 65535 # #每个nginx进程可以打开的最大文件数

Events {

Worker_connections 768; # #每个nginx进程允许的最大客户端连接数

#在nginx接到一个新连接通知后调用accept () to accept as many connections as possible

Multi_accept off;

}

HTTP {

##

# Basic Settings

##

Sendfile on; # #是否允许文件上传

Client_header_buffer_size 32k; # #上传文件大小限制

Tcp_nopush on; # #防止网络阻塞

Tcp_nodelay on; # #防止网络阻塞

Keepalive_timeout 65; # #允许客户端长连接最大秒数

# #nginx散列表大小, the larger the value, the greater the memory footprint, but the faster the routing

Types_hash_max_size 2048;

Access_log/var/log/nginx/access.log; # #访问日志文件路径名

Error_log/var/log/nginx/error.log # #错误日志文件路径名

      

# #如果两条用include命令加载站点配置文件

include/etc/nginx/conf.d/*.conf;

include/etc/nginx/sites-enabled/*;

}

server {

# #配置站点监听的端口

Listen 80;

      

Root/usr/share/nginx/html # #配置HTTP根页面目录

Index index.html index.htm; # #配置HTTP根目录中的默认页面

      

# #站点监听的IP地址, the default localhost is only available for native access, and it is generally necessary to change it to a real IP

server_name localhost;

# #location用于配置URL的转发接口

location/user/{

# #此配置http://server_name/user/Forwarding Address

Proxy_pass http://127.0.0.1:8080;

}

# #错误面页配置, the following configuration defines an HTTP 404 error for the display page/404.html

Error_page 404/404.html;

  

}

Linux source installation nginx and configuration

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.