颠末一段时间的利用,发明nginx在并发与负载本领方面确实优于apache,香港网存空间 北京主机,此刻已经将大部门站点从apache转到了nginx了。以下是nginx的一些简朴的安装设置。
情况
操纵系统:CentOS、RedHat
IP地点:192.168.1.202
下载软件包# mkdir /usr/local/src/tarbag
# mkdir /usr/local/src/software
# cd /usr/local/src/tarbag/
# wget http://www.nginx.org/download/nginx-1.0.6.tar.gz
# wget http://labs.frickle.com/files/ngx_cache_purge-1.3.tar.gz
编译安装# cd /usr/local/src/tarbag/
# tar -xzvf nginx-1.0.6.tar.gz -C /usr/local/src/software
# tar -xzvf ngx_cache_purge-1.3.tar.gz -C /usr/local/src/software
# cd /usr/local/src/software/
# ./configure
–prefix=/usr/local/nginx-1.0.6 # 安装路径
–with-http_stub_status_module # 启用nginx状态模块
–with-http_ssl_module # 启用SSL模块
–with-http_realip_module # 启用realip模块(将用户IP转发给后端处事器)
–add-module=../ngx_cache_purge-1.3 # 添加缓存排除扩展模块
# make
# make install
内核参数优化
# vi sysctl.conf 增加以下设置
net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = 1800
net.ipv4.ip_conntrack_max = 16777216 # 假如利用默认参数,容易呈现网络丢包
net.ipv4.netfilter.ip_conntrack_max = 16777216# 假如利用默认参数,容易呈现网络丢包
net.ipv4.tcp_max_syn_backlog = 65536
net.core.netdev_max_backlog = 32768
net.core.somaxconn = 32768
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries =
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.ip_local_port_range = 1024 65535
设置生效
# sysctl –p
修改iptables启动剧本,在star()函数内里加上
# vi /etc/init.d/iptables
/sbin/sysctl -p
设置典型站点站点
序号
目次
1
www.heytool.com
/www/html/www.heytool.com
2
bbs.heytool.com
/www/html/bbs.heytool.com
修改nginx设置文件:
# vi nginx.conf
user nobody nobody; # 运行nginx的所属组和所有者
worker_processes 2; # 开启两个nginx事情历程,一般几个CPU焦点就写几
error_log logs/error.log notice; # 错误日志路径
pid logs/nginx.pid; # pid路径
events {
worker_connections 1024; # 一个历程能同时处理惩罚1024个请求
}
http {
include mime.types;
default_type application/octet-stream;
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 logs/access.log main; # 默认会见日志路径
sendfile on;
keepalive_timeout 65; # keepalive超市时间
# 开始设置一个域名,一个server设置段一般对应一个域名
server {
listen 80; #
# 在本机所有ip上监听80,也可以写为192.168.1.202:80,这样的话,就只监听192.168.1.202上的80口
server_name www.heytool.com; # 域名
root /www/html/www.heytool.com; # 站点根目次(措施目次)
index index.html index.htm; # 索引文件
location / { # 可以有多个location
root /www/html/www.heytool.com; # 站点根目次(措施目次)
}
error_page 500 502 503 504 /50x.html;
# 界说错误页面,假如是500错误,则把站点根目次下的50x.html返回给用户
location = /50x.html {
root /www/html/www.heytool.com;
}
}
# 开始设置站点bbs.heytool.com
server {
listen 80;
server_name bbs.heytool.com;
root /www/html/bbs.heytool.com;
index index.html index.htm; # 索引文件
location / {
root /www/html/bbs.heytool.com;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /www/html/bbs.heytool.com;
}
}
}
Nginx启动封锁
# /usr/local/nginx-1.0.6/sbin/nginx //启动nginx
# /usr/local/nginx-1.0.6/sbin/nginx –t //测试nginx设置文件的精确性
# /usr/local/nginx-1.0.6/sbin/nginx –s reload //重载nginx
# /usr/local/nginx-1.0.6/sbin/nginx –s stop //封锁nginx
测试
建设测试站点
# mkdir –p /www/html/www.heytool.com
# mkdir –p /www/html/bbs.heytool.com
# echo “www.heytool.com” > /www/html/www.heytool.com/index.html
# echo “bbs.heytool.com” > /www/html/bbs.heytool.com/index.html
启动nginx
# /usr/local/nginx-1.0.6/sbin/nginx –t //看到ok和successful,说明设置文件没问题
nginx: the configuration file /usr/local/ nginx-1.0.6/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/ nginx-1.0.6/conf/nginx.conf test is successful
# /usr/local/nginx-1.0.6/sbin/nginx
绑定hosts,测试
把两个域名指向192.168.1.202
192.168.1.202 www.heytool.com
192.168.1.202 bbs.heytool.com
打开www.heytool.com,如下图:
打开bbs.heytool.com,如下图:
完毕!!!!
更多设置参考:http://www.docin.com/p-222277825.html
参考视频教程:http://www.kuaipan.cn/index.php?ac=file&oid=29331332391763978
文章推荐:
Haproxy+keepalived实现sphinx高可用负载平衡
利用haproxy来实现sphinx负载平衡与康健监测
耐久化存储系统ttserver的安装设置
版权说明 文章标题: nginx安装设置+清缓存模块安装