Home > Database > Mysql Tutorial > Centos下安装、Nginx笔记(一) 简单安装

Centos下安装、Nginx笔记(一) 简单安装

WBOY
Release: 2016-06-07 15:05:08
Original
979 people have browsed it

前期 安装 : 先 简单 安装 后期需要考虑内容: 1、要考虑Nginx自身的灾备/集群/负载均衡 2、没有对web节点进行健康检查 1、环境准备 Centos 5.4 Nginx 1.2.1 : wget http://www.nginx.org/download/nginx-1.2.1.tar.gz 2: 安装 步骤 # 安装 gcc编译器及相关

前期安装
     先简单安装
后期需要考虑内容:
1、要考虑Nginx自身的灾备/集群/负载均衡
2、没有对web节点进行健康检查

1、环境准备
Centos 5.4
Nginx 1.2.1 : wget http://www.nginx.org/download/nginx-1.2.1.tar.gz

2: 安装步骤
#安装gcc编译器及相关工具 yum -y install gcc gcc-c++ autoconf automake make
#安装相关依赖的模块 yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel


# cd /usr/local/src
# wget http://www.nginx.org/download/nginx-1.2.1.tar.gz
# tar -zxvf nginx-1.2.1.tar.gz            // 解压包

#./configure --prefix=/usr/local/nginx         //通过编译源码的方式进行安装
#make
#make install

配置文件:(配置和注释收集与网络)
#/usr/local/nginx/conf/nginx.config 
-----------------------------------------nginx.config----------------------------------------------------------------
#运行用户
#user  nobody;
#启动进程,通常设置成和cpu的数量相等
worker_processes  1;

#全局错误日志及PID文件
error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

#工作模式及连接数上限
events {
    use   epoll;             #epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以上内核,可以大大提高nginx的性能
    worker_connections  1024;#单个后台worker process进程的最大并发链接数
    # multi_accept on;
}

http {
         #设定mime类型,类型由mime.type文件定义
        include       /etc/nginx/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  /var/log/nginx/access.log main

      #sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,对于普通应用,
      #必须设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为 off,以平衡磁盘与网络I/O处理速度,降低系统的uptime.
      sendfile        on;
      #tcp_nopush     on;

        #连接超时时间
        #keepalive_timeout  0;
        keepalive_timeout  65;
        tcp_nodelay        on;

        #开启gzip压缩
        gzip  on;
        gzip_disable "MSIE [1-6]\.(?!.*SV1)";
        
        }

 
      server {
        #侦听80端口
            listen       80;
            #定义使用www.xx.com访问
            server_name  www.xx.com;
        
            #设定本虚拟主机的访问日志
            access_log  logs/www.xx.com.access.log  main;
        
        #默认请求
        location / {
              root   /usr/local/nginx/html;      #定义服务器的默认网站根目录位置
              index index.php index.html index.htm;   #定义首页索引文件的名称
        
            }
        
        # 定义错误提示页面
        error_page   500 502 503 504 /50x.html;
            location = /50x.html {
            root   /usr/local/nginx/html;
        }

------------------------------------------------------------------------------------------------------------------------------------


3、如何启动Nginx
#启动nginx
#./usr/local/nginx/sbin/nginx -t
显示以下信息为正确的

the configuration file <span>/</span>usr<span>/</span>local<span>/</span>nginx<span>/</span>conf<span>/</span>nginx.<span>conf</span> syntax is ok
configuration file <span>/</span>usr<span>/</span>local<span>/</span>nginx<span>/</span>conf<span>/</span>nginx.<span>conf</span> test is successful
Copy after login

启动成功后,查看nginx进程信息: # ps -ef | grep nginx ,看是否存在nginx的进程来确认是否成功启动。


#重启动nginx
#./usr/local/nginx/sbin/nginx -s reload

测试http://www.xx.com/
同时记得检查centos防火墙设置,是否开启了相应端口,可使用setup命令来设置防火墙、dns、网络等信息。
如果默认的配置文件未做任何改动,使用浏览器直接访问nginx server,会出现提示:Welcome to Nginx

4、优化
vim /etc/sysctl.conf
在最后添加(待详细研究)
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 = 2
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






2
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template