码迷,mamicode.com
首页 > 其他好文 > 详细

Nginx安装

时间:2016-09-03 06:22:54      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

nginx安装

依赖环境

yum -y install gcc zlib zlib-devel
yum -y install gcc openssl-devel zlib-devel

1. 下载好下面两个包:
nginx-1.8.1.tar.gz
pcre-8.36.tar.gz
2. 对pcre进行安装

 tar xf pcre-8.36.tar.gz -C /usr/src/
 ./configure --prefix=/usr/local/pcre --enable-utf8 --enable-jit
 make && make install

3. 安装nginx

#下载地址http://nginx.org/download/nginx-1.8.1.tar.gz
#tar xf nginx-1.8.1.tar.gz
# cd nginx-1.8.1
# ./configure --prefix=/usr/local/nginx --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/run/nginx/nginx.lock --user=daemon --group=daemon --with-pcre=/usr/src/pcre-8.36 --with-threads
#make && make install
##################注意:--with-pcre后面跟的是pcre的解压路径,赌五毛

-------------------------------------------------------------------
对nginx主配置文件进行修改

# cd /usr/local/nginx/
client_body_temp fastcgi_temp logs sbin uwsgi_temp
conf html proxy_temp scgi_temp
#conf:存放了nginx的配置文件
#html:网页存放目录
#sbin:nginx服务启动目录
#cd conf/
#vim nginx.conf #nginx的主配置文件

user daemon;
#主模块指令,指定 Nginx Worker 进程运行用户以及用户组,默认由 nobody 账号运行。
worker_processes 1;
#主模块指令,指定了 Nginx 要开启的进程数。每个 Nginx 进程平均耗费 10M~12M 内存。根据经验,一般指定一个进程足够了,如果是多核 CPU,建议指定和 CPU 的数量一样的进程数即可,可以用/proc/cpuinfo |grep process查看系统cpu数
error_log logs/error.log warn;
#主模块指令,用来定义全局错误日志文件。日志输出级别有debug、info、notice、warn、error、crit 可供选择,其中,debug 输出日志最为最详细,而 crit 输出日志最少。
pid /var/run/nginx/nginx.pid;
#主模块指令,用来指定进程 id 的存储文件位置。
events {
#设定 Nginx 的工作模式及连接数上限
worker_connections 1024;
#worker_connections 也是个事件模块指令,用于定义 Nginx 每个进程的最大连接数,默认是 1024.最大客户端连接数由 worker_processes 和worker_connections 决定,即Max_client=worker_processes*worker_connections,在作为反向代理时,max_clients 变为:max_clients = worker_processes * worker_connections/4进程的最大连接数受 Linux 系统进程的最大打开文件数限制,在执行操作系统命令“ulimit -n 65536”后 worker_connections 的设置才能生效。
}
#下面这段内容是 Nginx 对 HTTP 服务器相关属性的配置
http {
include mime.types;
#主模块指令,实现对配置文件所包含的文件的设定,可以减少主配置文件的复杂度。类似于 Apache 中的 include 方法。
default_type application/octet-stream;
#属于 HTTP 核心模块指令,这里设定默认类型为二进制流,也就是当文件类型未定义时使用这种方式,例如在没有配置 PHP 环境时,Nginx 是不予解析的,此时,用浏览器访问 PHP 文件就会出现下载窗口。
#log_format 是 Nginx 的 HttpLog 模块指令,用于指定 Nginx 日志的输出格式。main 为此日志输出格式的名称,可以在下面的 access_log 指令中引用。
log_format main $remote_addr - $remote_user [$time_local] "$request" 
$status $body_bytes_sent "$http_referer" 
"$http_user_agent" "$http_x_forwarded_for";
access_log /var/log/nginx/access.log main;
#client_max_body_size 20m; 用来设置允许客户端请求的最大的单个文件字节数。
#client_header_buffer_size 32K; 用于指定来自客户端请求头的 headerbuffer 大小。对于大多数请求,1K 的缓冲区大小已经足够,如果自定义了消息头或有更大的 Cookie,可以增加缓冲区大小。这里设置为 32K。
#large_client_header_buffers 4 32k; 用来指定客户端请求中较大的消息头的缓存最大数量和大小,“4”为个数,“32K”为大小,最大缓存量为 4 个 32K。
sendfile on; #用于开启高效文件传输模式。 tcp_nopush 和 tcp_nodelay 两个指令设置为将on 用于防止网络阻塞。
tcp_nopush on;
keepalive_timeout 10;
#设置客户端连接保持活动的超时时间。在超过这个时间之后,服务器会关闭该连接。
#下面配置 Nginx 的 HttpGzip 模块。这个模块支持在线实时压缩输出数据流
gzip on; #用于设置开启或者关闭 gzip 模块,“gzip on”表示开启 GZIP 压缩,实时压缩输出数据流。
gzip_min_length 2k; #设置允许压缩的页面最小字节数,页面字节数从 header 头的Content-Length 中获取。默认值是 0,不管页面多大都进行压缩。建议设置成大于 1K 的字节数,小于 1K 可能会越压越大。
gzip_buffers 4 8k; #表示申请 4 个单位为 8K 的内存作为压缩结果流缓存,默认值是申请与原始数据大小相同的内存空间来存储 gzip 压缩结果。
gzip_http_version 1.1; #用于设置识别 HTTP 协议版本,默认是 1.1,目前大部分浏览器已经支持 GZIP 解压,使用默认即可。
gzip_comp_level 6; #用来指定 GZIP 压缩比, 压缩比最小,1处理速度最快; 压缩比最大,9传输速度快,但处理最慢,也比较消耗 cpu 资源。
gzip_types test/plain application/x-javascript test/css application/xmli application/xml+rss test/javascript image/jpg image/gif image/png; #用来指定压缩的类型,无论是否指定,“text/html”类型总是会被压缩的


#下面介绍对虚拟主机的配置。建议将对虚拟主机进行配置的内容写进另外一个文件,然后通过include 指令包含进来,这样更便于维护和管理。

server { #server 标志定义虚拟主机开始
listen 80; #listen 用于指定虚拟主机的服务端口
server_name www.sxkj.com; #用来指定 IP 地址或者域名,多个域名之间用空格分开
charset utf-8; #设置网页的默认编码格式。

#access_log logs/host.access.log main; #用来指定此虚拟主机的访问日志存放路径,最后的 main 用于指定访问日志的输出格式。
location / { #指定虚拟主机的根目录
root /web/;
index index.html index.htm;
}
#error_page 404 /404.html;

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

location = /404.html {
root /web/error;
}

 

-------------------------------------------------------------------
# cat /proc/cpuinfo |grep process //查看系统
processor : 0

# /usr/local/nginx/sbin/nginx \\启动nginx
# /usr/local/nginx/sbin/nginx -s stop \\停止nginx
# /usr/local/nginx/sbin/nginx -s reload \\重载配置文件

Nginx安装

标签:

原文地址:http://www.cnblogs.com/losbyday/p/5836119.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!