部署高性能Web服务器 – Nginx的

1、安装基本独立软件包

YUM -Y安装gcc openssl-devel pcre-devel zlib-devel

2、部署nginx

USERADD NGINX -S /SBIN /NOLOGIN #ADD NGINX用户

tar zxvf nginx-1.2.7.ta​​r.gz #uncompress nginx tar.gz软件包.

CD NGINX-1.2.7

./配置 \

–用户=nginx \ # 用户是nginx

–组=nginx \ #用户组为nginx

–前缀=/usr/local/nginx/ \ # NGINX HOME PATH

–with-http_stub_status_module \

–使用HTTP_SSL_MODULE #SSL模块

# 有关更多参数,您可以重新订阅此命令

./配置 –救命

nginx路径前缀: “/USR/local/nginx”

nginx二进制文件: “/usr/local/nginx/sbin/nginx”

NGINX配置前缀: “/USR/local/nginx/conf”

nginx配置文件: “/usr/local/nginx/conf/nginx.conf”

Nginx PID文件: “/usr/local/nginx/logs/nginx.pid”

nginx错误日志文件: “/usr/local/nginx/logs/error.log”

nginx http访问日志文件: “/usr/local/nginx/logs/access.log”

nginx http客户端请求身体临时文件: “client_body_temp”

nginx http代理临时文件: “proxy_temp”

nginx http fastcgi临时文件: “fastcgi_temp”

 

使 & 进行安装

 

检查nginx中的配置是否正确

安装后.

/usr/local/nginx/sbin/nginx –v

 

3、配置nginx

CD/USR/local/nginx/conf/

RM -RF nginx.conf

vim nginx.conf

将以下配置粘贴到nginx.conf

用户 nginx nginx; #用户和用户组

worker_processes 8; #nginx启动时的过程数量

error_log logs/nginx_error.log crit; #错误日志和日志级别

pid/usr/local/nginx/nginx.pid; #PID文件路径

worker_rlimit_nofile 51200;

大事记

{

使用 epoll; # EPOLL模块

worker_connections 51200; #每个过程的最大允许连接.

}

http

{

包括mime.types;

default_type 应用程序/八位字节流;

#Charset GB2312;

server_names_hash_bucket_size 128;

client_header_buffer_size 32k;

large_client_header_buffers 4 32ķ;

sendfile;

tcp_nopush 开启;

keepalive_timeout 60;

tcp_nodelay 开启;

fastcgi_connect_timeout 300;

fastcgi_send_timeout 300;

fastcgi_read_timeout 300;

fastcgi_buffer_size 64k;

fastcgi_buffers 4 64ķ;

fastcgi_busy_buffers_size 128k;

fastcgi_temp_file_write_size 128k;

gzip 上;

gzip_min_length 1k;

gzip_buffers 4 16ķ;

gzip_http_version 1.0;

gzip_comp_level 2;

gzip_types text/plain应用程序/x-javaScript文本/css应用程序/xml;

gzip_vary on;

#limit_zone crawler $ binary_remote_addr 10m;

服务器

{

听 80;

server_name localhost; #主机名或服务器名称

index index.html index.htm index.php; # 默认主页名称.

根目录 /usr/local/nginx/html; #网站中的根目录

位置 / {

根HTML;

index index.html index.htm;

}

limit_conn crawler 20;

#FastCGI可以支持PHP

位置~ .*\.(php|PHP5)?$

{

#fastcgi_pass unix:/TMP/php-cgi.sock;

fastcgi_pass 127.0.0.1:9000; #fastcgi侦听端口 9000

fastcgi_index index.php;

包括fcgi.conf; #FastCG配置文件.

}

#对于一种静态文件 , 您可以设置长时间的缓存时间

位置~ .*\.(gif|jpg|JPEG格式|PNG|bmp|瑞士法郎|js|css)$

{

30天到期;

}

#日志格式

log_format access ‘$remote_addr – $远程用户 [$时间_本地] “$要求” ‘

'$status $body_bytes_sent “$http_referer” ‘

‘”$http_user_agent” $http_x_forwarded_for';

access_log logs/access.log访问;

}

}

保存并退出!

 

笔记 : 这是一批文件概括,如果您愿意,您需要再次编辑

配置其他功能.

4、启动nginx,并检查工作状态

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

聚苯乙烯 | grep nginx

Netstat -nltp | 格雷普 80

链接 127.0.0.1 # 如果 “欢迎来到nginx!” 出现了, 此指示nginx启动成功

或者您可以输入 “本地主机” 在Web Brower的URL栏中 , 如果你看过 “欢迎来到nginx!”

这意味着Nginx Starup成功

发表评论