`
ssydxa219
  • 浏览: 608736 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

Nginx

 
阅读更多

root

 

yum install pcre pcre-devel

yum install zlib zlib-devel

yum install openssl openssl-devel

 

创建目录(nginx-src)并进去;然后,从官方地址(http://nginx.org/)下载,解压,配置,编译,安装:

# mkdir nginx-src && cd nginx-src
# wget http://nginx.org/download/nginx-1.7.3.tar.gz
# tar xzf nginx-1.7.3.tar.gz
# cd nginx-1.7.3
# ./configure
# make
# make install
# whereis nginx
nginx: /usr/local/nginx

默认的安装路径为:/usr/local/nginx;跳转到这里,便可以启动或停止它了。

 

# ./nginx -h
nginx version: nginx/1.7.3
Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /usr/local/nginx/)
  -c filename   : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file

 

启动:nginx
停止:nginx -s stop

 


3、添加到系统服务
使用命令“# vi /etc/init.d/nginx”,打开编辑器,输入如下内容:

#! /bin/sh
# chkconfig: 2345 85 15
# Startup script for the nginx Web Server
# description: nginx is a World Wide Web server.
# It is used to serve HTML files and CGI.
# processname: nginx
# pidfile: /usr/local/nginx/logs/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx deamon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
SCRIPTNAME=/etc/init.d/$NAME

test -x $DAEMON || exit 0

d_start(){
  $DAEMON || echo -n "already running"
}

d_stop(){
  $DAEMON -s quit || echo -n "not running"
}


d_reload(){
  $DAEMON -s reload || echo -n "can not reload"
}

case "$1" in
start)
  echo -n "Starting $DESC: $NAME"
  d_start
  echo "."
;;
stop)
  echo -n "Stopping $DESC: $NAME"
  d_stop
  echo "."
;;
reload)
  echo -n "Reloading $DESC conf..."
  d_reload
  echo "reload ."
;;
restart)
  echo -n "Restarting $DESC: $NAME"
  d_stop
  sleep 2
  d_start
  echo "."
;;
*)
  echo "Usage: $ScRIPTNAME {start|stop|reload|restart}" >&2
  exit 3
;;
esac

exit 0

保存退出后,再使用下面的命令,使其可执行;然后,添加配置并查看。
可用chkconfig修改其值,也可用ntsysv工具改变是否自启动。

 

# chmod +x /etc/init.d/nginx
# chkconfig --add nginx
# chkconfig nginx on/off
# chkconfig --list nginx
nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off

 

 

 

 

 

 

 

一般我们都需要先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩。

 

1.选定源码目录

 

选定目录 /usr/local/

 

 

 

cd /usr/local/

 

 

 

2.安装PCRE

 

cd /usr/local/

 

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

 

tar -zxvf pcre-8.21.tar.gz

 

cd pcre-8.21

 

./configure

 

make

 

make install

 

 

 

3.安装zlib

 

cd /usr/local/ 

 

wget http://zlib.net/zlib-1.2.8.tar.gz

 

tar -zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8

 

./configure

 

make

 

make install

 

 

 

4.安装ssl

 

 

 

cd /usr/local/

 

wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz

 

tar -zxvf openssl-1.0.1c.tar.gz

 

./config

 

make

 

make install

 

 

 

5.安装nginx

 

 

 

Nginx 一般有两个版本,分别是稳定版和开发版,您可以根据您的目的来选择这两个版本的其中一个,下面是把 Nginx 安装到 /usr/local/nginx 目录下的详细步骤:

 

 

 

cd /usr/local/

 

wget http://nginx.org/download/nginx-1.2.8.tar.gz

 

tar -zxvf nginx-1.2.8.tar.gz

 

cd nginx-1.2.8  

 

./configure --prefix=/usr/local/nginx 

 

make

 

make install

 

 

 

--with-pcre=/usr/src/pcre-8.21 指的是pcre-8.21 的源码路径。

 

--with-zlib=/usr/src/zlib-1.2.7 指的是zlib-1.2.7 的源码路径。

 

 

 

6.启动

 

确保系统的 80 端口没被其他程序占用,

 

/usr/local/nginx/sbin/nginx

 

 

 

检查是否启动成功:

 

netstat -ano|grep 80 有结果输入说明启动成功

 

 

 

 

 

打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功。

 

 

 

7.重启

 

/usr/local/nginx/sbin/nginx –s reload

 

 

 

8.修改配置文件

 

cd /usr/local/nginx/conf

 

vi nginx.conf

 

 

 

9.常用配置

 

#nginx运行用户和组

 

user    www www;  

 

#启动进程,通常设置成和cpu的数量相等

 

worker_processes  4;

 

 

 

#全局错误日志及PID文件

 

pid /var/run/nginx.pid;

 

error_log  /var/log/nginx/error.log;

 

 

 

events {

 

        #epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以上内核,可以大大提高nginx的性能

 

use epoll;

 

                   #单个后台worker process进程的最大并发链接数

 

        worker_connections  10240;

 

}

 

#设定http服务器,利用它的反向代理功能提供负载均衡支持

 

http {

 

        include       mime.types;

 

 

 

        default_type  application/octet-stream;

 

 

 

         error_page 400 403 500 502 503 504  /50x.html;

 

 

 

        index index.html index.shtml

 

 

 

        autoindex off;

 

 

 

         fastcgi_intercept_errors on;

 

 

 

        sendfile        on;

 

 

 

        # These are good default values.

 

        tcp_nopush      on;

 

        tcp_nodelay     off;

 

 

 

        # output compression saves bandwidth

 

        gzip  off;

 

         #gzip_static on;

 

        #gzip_min_length  1k;

 

        gzip_http_version 1.0;

 

        gzip_comp_level 2;

 

        gzip_buffers  4 16k;

 

        gzip_proxied any;

 

        gzip_disable "MSIE [1-6]\.";

 

        gzip_types  text/plain text/html text/css application/x-javascript application/xml application/xml+rss text/javascript;

 

        #gzip_vary on;

 

 

 

        server_name_in_redirect off;

 

 

 

#设定负载均衡的服务器列表

 

        upstream portals {

 

                  server 172.16.68.134:8082 max_fails=2 fail_timeout=30s;

 

                  server 172.16.68.135:8082 max_fails=2 fail_timeout=30s;

 

                            server 172.16.68.136:8082 max_fails=2 fail_timeout=30s;

 

                  server 172.16.68.137:8082 max_fails=2 fail_timeout=30s;

 

        }

 

 

 

        #upstream overflow {

 

         #       server 10.248.6.34:8090 max_fails=2 fail_timeout=30s;       

 

         #       server 10.248.6.45:8080 max_fails=2 fail_timeout=30s;       

 

        #}

 

 

 

        server {

 

                                     #侦听8080端口

 

                listen       8080;

 

                server_name  127.0.0.1;

 

 

 

                   #403404页面重定向地址

 

                   error_page  403 = http://www.e100.cn/ebiz/other/217/403.html;

 

                   error_page  404 = http://www.e100.cn/ebiz/other/218/404.html;

 

                   proxy_connect_timeout      90;

 

                   proxy_send_timeout         180;

 

                   proxy_read_timeout         180;

 

 

 

                   proxy_buffer_size 64k;

 

                   proxy_buffers 4 128k;

 

                   proxy_busy_buffers_size 128k;

 

 

 

 

 

                   client_header_buffer_size 16k;

 

                   large_client_header_buffers 4 64k;

 

 

 

                #proxy_send_timeout         3m;

 

                #proxy_read_timeout         3m;

 

                #proxy_buffer_size          4k;

 

                #proxy_buffers              4 32k;

 

 

 

                proxy_set_header Host $http_host;

 

                proxy_max_temp_file_size 0;

 

                #proxy_hide_header Set-Cookie;

 

                  

 

         #       if ($host != 'www.e100.cn' ) {

 

         #                rewrite ^/(.*)$ http://www.e100.cn/$1 permanent;

 

         #       }

 

 

 

 

 

               location / {

 

                       deny all;

 

               }

 

 

 

                   location ~ ^/resource/res/img/blue/space.gif {

 

                    proxy_pass http://tecopera;

 

               }

 

 

 

               location = / {

 

                   rewrite ^(.*)$  /ebiz/event/517.html last;

 

               }

 

 

 

 

 

 

 

                   location = /ebiz/event/517.html {

 

                    add_header Vary Accept-Encoding;

 

                    root /data/web/html;

 

                    expires 10m;

 

               }

 

 

 

 

 

 

 

 

 

               location = /check.html {

 

                    root /usr/local/nginx/html/;

 

                    access_log off;

 

               }

 

 

 

               location = /50x.html {

 

                    root /usr/local/nginx/html/;

 

                    expires 1m;

 

                    access_log off;

 

               }

 

 

 

 

 

              location = /index.html {

 

                       add_header Vary Accept-Encoding;

 

#定义服务器的默认网站根目录位置

 

                    root /data/web/html/ebiz;

 

                    expires 10m;

 

               }

 

#定义反向代理访问名称

 

                   location ~ ^/ecps-portal/* {

 

                   # expires 10m;

 

#重定向集群名称

 

                    proxy_pass http://portals;

 

                    #proxy_pass http://172.16.68.134:8082;

 

               }

 

 

 

                   location ~ ^/fetionLogin/* {

 

                   # expires 10m;

 

                    proxy_pass http://portals;

 

                    #proxy_pass http://172.16.68.134:8082;

 

                }

 

 

 

                   #location  ~ ^/business/* {                                                                      

 

                #   # expires 10m;                                                                                

 

                #    proxy_pass http://172.16.68.132:8088;                                                                   

 

                #    #proxy_pass http://172.16.68.134:8082;                                                       

 

                #}

 

 

 

                   location ~ ^/rsmanager/* {

 

                    expires 10m;

 

                    root /data/web/;

 

                    #proxy_pass http://rsm;

 

               }

 

#定义nginx处理的页面后缀

 

                   location ~* (.*)\.(jpg|gif|htm|html|png|js|css)$  {

 

                            root /data/web/html/;

 

#页面缓存时间为10分钟

 

                         expires 10m;

 

                   }

 

 

 

#设定查看Nginx状态的地址     

 

               location ~* ^/NginxStatus/ {

 

                    stub_status on;

 

                    access_log off;

 

                    allow 10.1.252.126;

 

                    allow 10.248.6.49;

 

                    allow 127.0.0.1;

 

                    deny all;

 

               }

 

         #       error_page   405 =200 @405;

 

         #       location @405

 

         #       {

 

         #                proxy_pass http://10.248.6.45:8080;

 

         #       }  

 

 

 

               access_log  /data/logs/nginx/access.log combined;

 

               error_log   /data/logs/nginx/error.log;

 

        }

 

         server {

 

                listen       8082;

 

 

 

                server_name  _;

 

               location = /check.html {

 

                    root /usr/local/nginx/html/;

 

                    access_log off;

 

               }

 

                  

 

        }

 

         server {

 

                   listen       8088;

 

                   server_name  _;

 

                   location ~ ^/* {

 

                   root /data/web/b2bhtml/;

 

                   access_log off;

 

         }                

 

         }

 

        server {

 

                listen       9082;

 

                server_name  _;

 

 

 

        #        location ~ ^/resource/* {

 

        #            expires 10m;

 

         #           root /data/web/html/;

 

         #       }

 

 

 

                location  / {

 

                     root /data/web/html/sysMaintain/;

 

                       if (!-f $request_filename) {

 

                            rewrite ^/(.*)$ /sysMaintain.html last;

 

                           }

 

                }

 

        }

 

 

}

 

 

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

 

 

一.安装

安装Nginx需要如下lib,在附件中提供下载,将他们拷贝至 /usr/local/src

 

安装命令如下:

// 安装 pcre
tar -xvzf pcre-8.35.tar.gz 
cd pcre-8.35
./configure 
make
make test
sudo make install

// 安装 zlib
tar -xvzf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make
make test
make install
whereis zlib

// 安装 openssl
tar -xvzf openssl-1.0.1h.tar.gz
cd openssl-1.0.1h
./config 
make
make test
make install

// 安装 nginx
tar -xvzf nginx-1.7.2.tar.gz
cd nginx-1.7.2
./configure 
--sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-pcre=/usr/local/src/pcre-8.35 \
--with-zlib=/usr/local/src/zlib-1.2.8 \
--with-openssl=/usr/local/src/openssl-1.0.1h   
make
make test
make install

二.启动和停止

1.启动

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

参数“-c”指定了配置文件的路径,如果不加“-c”参数,Nginx会默认加载其安装目录的conf子目录中的nginx.conf文件

2.查看进程

ps -ef  | grep nginx
cat /usr/local/nginx/logs/nginx.pid

3.停止

sudo kill -QUIT 主进程号
sudo pkill -9 nginx

三. 一些问题

1.查看80端口占用情况

sudo netstat -tlnp|grep 80

2.启动时出现如下问题

/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

解决方法

ldd $(which /usr/local/nginx/sbin/nginx)
find / -type f -name *libpcre.so.* 
发现 /lib64/libpcre.so.0.0.1
cd /lib64
ln -s libpcre.so.0.0.1 libpcre.so.1

 

 

 

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

 

1、安装Zlib函数库

####Gcc编译环境是必须条件#####[root@i-it ~]# yum install gcc-c++ make autoconf aotomake
[root@i-it ~]# tar zxf zlib-1.2.8.tar.gz 
[root@i-it ~]# cd zlib-1.2.8[root@i-it zlib-1.2.8]#./configure --prefix=/software/zlib
[root@i-it zlib-1.2.8]# make && make install

 

2、添加对rewrite的支持,编译参数中启用了对utf8字符的支持,以便nginx支持中文的正则表达式

[root@i-it ~]# tar zxf pcre-8.35.tar.gz 
[root@i-it ~]# cd pcre-8.35[root@i-it pcre-8.35]#./configure --prefix=/software/pcre --enable-utf8 --enable-unicode-properties
[root@i-it pcre-8.35]# make && make install

 

3、添加对https 的支持

[root@i-it ~]# tar zxf openssl-1.0.1h.tar.gz 
[root@i-it ~]# cd openssl-1.0.1h[root@i-it openssl-1.0.1h]#./config --prefix=/software/openssl
[root@i-it openssl-1.0.1h]# make && make install

 

编译TCMalloc,它是由Google公司发开的一款开源工具,goole-perftools中的一成员,TCMalloc在内存的分配效率和速度 要比标准的glibc库好得多,它不但可以用来优化高并发下的Mysql,从而降低系统的负载,还可以用于Nginx实现同样的功能,因此,对于高并发的 Nginx来说无疑是如虎添翼。

 

4、安装libunwind库

[root@i-it ~]# tar zxf libunwind-1.1.tar.gz 
[root@i-it ~]# cd libunwind-1.1[root@i-it libunwind-1.1]# CFLAGS=-fPIC ./configure --prefix=/software/google-libunwind
[root@i-it libunwind-1.1]# make CFLAGS=-fPIC && make CFLAGS=-fPIC install

 

5、安装google-perftools

[root@i-it ~]# tar zxf gperftools-2.2.tar.gz 
[root@i-it ~]# cd gperftools-2.2[root@i-it gperftools-2.2]# LDFLAGS="-L/software/google-libunwind/lib" CPPFLAGS="-I/software/google-libunwind/include"./configure --prefix=/software/google-perftools
[root@i-it gperftools-2.2]# make && make install

 

6、添加共享库路径

[root@i-it ~]# echo "/software/google-libunwind/lib/">>/etc/ld.so.conf
[root@i-it ~]# echo "/software/google-perftools/lib/">>/etc/ld.so.conf
[root@i-it ~]# echo "/software/zlib/lib/">>/etc/ld.so.conf
[root@i-it ~]# echo "/software/pcre/lib/">>/etc/ld.so.conf
[root@i-it ~]# ldconfig -v

 

7、编译Nginx

[root@i-it ~]# groupadd -g 1500 nginx
[root@i-it ~]# useradd -M -u 1500-g nginx -s /sbin/nologin nginx
[root@i-it ~]# mkdir /var/tmp/nginx
[root@i-it ~]# chown nginx:nginx /var/tmp/nginx/[root@i-it ~]# tar zxf nginx-1.7.1.tar.gz 
[root@i-it ~]# cd nginx-1.7.1#############注释该文件的174行取消debug模式##############[root@i-it nginx-1.7.1]# vi auto/cc/gcc 
    173# debug174# CFLAGS="$CFLAGS -g"######因为google-perftools库的安装路径并非默认,所以这里又要修改一次源码####[root@i-it nginx-1.7.1]# sed -i "s#/usr/local#/software/google-perftools#"auto/lib/google-perftools/conf
[root@i-it nginx-1.7.1]#./configure --prefix=/software/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module --with-google_perftools_module --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 --with-pcre=/root/pcre-8.35--with-openssl=/root/openssl-1.0.1h--with-zlib=/root/zlib-1.2.8[root@i-it nginx-1.7.1]# make && make install

 

8、先添加一个启动脚本,让Nginx run起来

[root@i-it ~]# vi /etc/init.d/nginx
#!/bin/bash# nginx Startup script for the Nginx HTTP Server# it is v.0.0.2 version.# chkconfig: - 85 15# description: Nginx is a high-performance web and proxy server.# It has a lot of features, but it's not for everyone.# processname: nginx# pidfile: /software/nginx/logs/nginx.pid# config: /software/nginx/conf/nginx.conf
nginxd=/software/nginx/sbin/nginx
nginx_config=/software/nginx/conf/nginx.conf
nginx_pid=/software/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"# Source function library../etc/rc.d/init.d/functions
# Source networking configuration../etc/sysconfig/network
# Check that networking is up.[ ${NETWORKING}="no"]&&exit0[-x $nginxd ]||exit0# Start nginx daemons functions.
start(){if[-e $nginx_pid ];then
echo "nginx already running...."exit1fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL =0]&& touch /var/lock/subsys/nginx
return $RETVAL
}# Stop nginx daemons functions.
stop(){
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL =0]&& rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid
}
reload(){
echo -n $"Reloading $prog: "#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}# See how we were called.case"$1"in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?;;*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"exit1esacexit $RETVAL

#########赋权让其run起来#########[root@i-it ~]# chmod 755/etc/init.d/nginx && chkconfig nginx on
[root@i-it ~]# service nginx start
Starting nginx:[  OK  ][root@i-it ~]# netstat -pant | grep 80
tcp        000.0.0.0:800.0.0.0:*                   LISTEN      37831/nginx      

 

9、Nginx run起来了,配置前面的google-perftools库

#####创建线程目录#####[root@i-it ~]# mkdir /tmp/tcmalloc
[root@i-it ~]# chmod 0777/tmp/tcmalloc/####修改Nginx配置文件#####[root@i-it ~]# vi /software/nginx/conf/nginx.conf
pid        logs/nginx.pid;
google_perftools_profiles /tmp/tcmalloc;###查看google-perftools是否加载###[root@i-it ~]# service nginx restart
Stopping nginx:[  OK  ]Starting nginx:[  OK  ][root@i-it ~]#  lsof -n | grep tcmalloc  
nginx     37882   nginx    9w      REG              253,001179654/tmp/tcmalloc.37882
nginx     37883   nginx   11w      REG              253,001179655/tmp/tcmalloc.37883####每一行输出的数据表示Nginx主配置文件中worker_processes的值,其每个线程文件后面的数值为Nginx启动的PID####[root@i-it ~]# ps aux | grep nginx
root     378800.00.230200892?Ss00:270:00 nginx: master process /software/nginx/sbin/nginx -c /software/nginx/conf/nginx.conf
nginx    378820.01.1348043844?        S    00:270:00 nginx: worker process                                        
nginx    378830.01.1348043772?        S    00:270:00 nginx: worker process          
####iptables 开80端口####[root@i-it ~]# iptables -I INPUT -p tcp --dport 80-j ACCEPT

1、关闭系统中不需要的服务

###minimal  本来就是最小安装,这里我也就不提建议了,跟着自己的环境来###[root@i-it ~]# chkconfig --list
auditd         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
blk-availability	0:off	1:on	2:on	3:on	4:on	5:on	6:off
crond          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
ip6tables      	0:off	1:off	2:on	3:on	4:on	5:on	6:off
iptables       	0:off	1:off	2:on	3:on	4:on	5:on	6:off
iscsi          	0:off	1:off	2:off	3:on	4:on	5:on	6:off
iscsid         	0:off	1:off	2:off	3:on	4:on	5:on	6:off
lvm2-monitor   	0:off	1:on	2:on	3:on	4:on	5:on	6:off
mdmonitor      	0:off	1:off	2:on	3:on	4:on	5:on	6:off
multipathd     	0:off	1:off	2:off	3:off	4:off	5:off	6:off
netconsole     	0:off	1:off	2:off	3:off	4:off	5:off	6:off
netfs          	0:off	1:off	2:off	3:on	4:on	5:on	6:off
network        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
nginx          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
postfix        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
rdisc          	0:off	1:off	2:off	3:off	4:off	5:off	6:off
restorecond    	0:off	1:off	2:off	3:off	4:off	5:off	6:off
rsyslog        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
saslauthd      	0:off	1:off	2:off	3:off	4:off	5:off	6:off
sshd           	0:off	1:off	2:on	3:on	4:on	5:on	6:off
udev-post      	0:off	1:on	2:on	3:on	4:on	5:on	6:off

 
2、清除文件描述符

###建议先备份一下###[root@i-it ~]# ll /software/nginx/sbin/nginx  -h
-rwxr-xr-x.1 root root 2.9MJun800:02/software/nginx/sbin/nginx
[root@i-it ~]# strip /software/nginx/sbin/nginx 
[root@i-it ~]# ll /software/nginx/sbin/nginx  -h
-rwxr-xr-x.1 root root 2.6MJun801:54/software/nginx/sbin/nginx

 
2、优化写磁盘操作

####重新挂载当前分区,不记录Nginx对文件访问的时间修改####
mount -o defaults,noatime,nodiratime -o remount /dev/sda1

 
3、优化文件描述符

####修改配置文件####[root@i-it ~]# egrep -v "^#|^$"/etc/security/limits.conf
*-       nofile          65535*-       nproc           65535[root@i-it ~]# su -[root@i-it ~]# ulimit -u
65535[root@i-it ~]# ulimit -n
65535

 
4、优化内核参数

[root@i-it ~]# cat >/etc/sysctl.conf<

 

 

分享到:
评论

相关推荐

    一分钟搞定 Nginx反向代理 nginx域名代理

    3.找到D:\nginx\conf下nginx.conf文件用记事本打开 在文段末尾大括号前加上 include proxy.conf;(就是加载刚刚新建的那个文件(注意路径)) 4.进入cmd 进入D盘: d: 进到nginx文件夹下:cd nginx 启动nginx.exe:...

    nginx-upstream-jvm-route 和 nginx 对应版本,亲测可用

    此资源有两个文件,含 nginx-upstream-jvm-route 和 nginx 对应版本,都是tar.gz文件。 安装方法网上很多就不写了,亲测可用。 不用担心版本不匹配造成安装失败,再浪费积分去到处下载尝试的烦恼。 此资源有两个文件...

    Nginx 1.22.0 Linux 版本,解压安装。

    Nginx 1.22.0 Linux 版本,解压安装。 Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,在BSD-like 协议下发行。其特点是占有内存少,并发能力强,事实上nginx的并发能力在同类型...

    nginx-1.23.1.zip

    nginx/Windows-1.23.1 Nginx(发音为“engine X”[9] /ˌɛndʒɪnˈɛks/ EN-jin-EKS),风格化为NGIИX,是一个Web服务器,也可以用作反向代理,负载平衡器,邮件代理和HTTP缓存。该软件由Igor Sysoev创建,并于...

    Nginx 全能HTTP+Web 指南 完整版pdf

    Nginx全能指南是一本介绍Nginx服务器的书,首先,简要介绍Nginx的基本概念和作用,如反向代理、负载均衡等。然后,列举Nginx的优点,如高性能、可扩展性、稳定性等。接着,介绍如何安装和配置Nginx,并提供一些实用...

    使用nginx部署前端项目(超详细教程).pdf

    使用nginx部署前端项目是一篇非常详细的教程,旨在帮助初学者使用Nginx来部署前端项目。本文首先介绍了Nginx的基本概念和作用,解释了为什么Nginx是一个强大的Web服务器和反向代理。然后,文章详细讲解了如何在Linux...

    Nginx服务器的安装与配置.pdf

    Nginx官网配置.pdf Nginx基本配置.pdf Nginx模块.pdf Nginx指南.pdf 第1章 Nginx简介.pdf 第2章 Nginx服务器的安装与配置.pdf 第3章 Nginx的基本配置与优化.pdf 第4章 Nginx与PHP(FastCGI)的安装、配置与优化.pdf 第...

    nginx-1.19.3-http-flv.zip

    资源说明: 1. 采用nginx最新版编译,包含最新的nginx-http-flv-module,以及基础模块openssl、prce、zlib 2. 整体打包,已配置好nginx.conf的http-flv直播流,以及http web环境...3. 使用nginxservice.exe install安装

    nginx常用依赖包.rar

    本压缩包均为linux 64位系统的,其中包含nginx-1.14.2.tar.gz、nginx-1.15.4.tar.gz、nginx-1.16.1.tar.gz、nginx-1.17.5.tar.gz及pcre-8.41.tar.gz、pcre-8.42.tar.gz、pcre-8.43.tar.gz、pcre-8.44.tar.gz及...

    Nginx启动、重启失败的一般解决方法和步骤

    也可以通过查看Nginx日志文件定位到Nginx重启失败的原因,Nginx日志文件的路径一般在:/var/log/nginx目录下 总结 文章没什么技术含量,每天都攒一点基础知识 您可能感兴趣的文章:nginx centos 服务开机启动设置...

    linux服务器上使用nginx访问本地静态资源的方法

    vim /etc/nginx/conf.d/nginx.conf 5.重启nginx服务 service nginx restart 6.页面尝试访问本地资源 7.访问成功! 总结 以上所述是小编给大家介绍的linux服务器上使用nginx访问本地静态资源的方法,希望对大家...

    Nginx配置统计流量带宽请求及记录实时请求状态的方法

    ngx_req_status用来展示nginx请求状态信息,类似于apache的status,nginx自带的模块只能显示连接数等等信息,我们并不能知道到底有哪些请求、以及各url域名所消耗的带宽是多少。ngx_req_status提供了这些功能. 功能...

    nginx 离线安装包nginx 离线安装包

    nginx 离线安装包nginx 离线安装包

    nginx-sticky-module-1.25.zip

    nginx sticky是nginx的module,可以实现基于cookie的负载均衡。 下载后,在编译安装nginx时,用--add-module选项,指到sticky所在目录。类似命令如下: ./configure --prefix=/usr/local/nginx-1.6.0 --add-module=...

    nginx-1.18.0离线安装依赖包及过程

    nginx-1.18安装步骤 附件上传至服务器/opt/nginx cd /opt/nginx tar zxvf zlib-1.2.11.tar.gz cd zlib-1.2.11 ./configure make make install tar zxvf pcre-8.40.tar.gz cd pcre-8.40 ./configure make make ...

    Nginx文件上传模块配置

    Nginx是一个高性能的HTTP和反向代理服务器,也是IMAP/POP3/SMTP代理服务器,是由俄罗斯人lgor Sysoev开发,支持模块加载和卸载,其中upload_module和upload_progress_module就是第三方开发的模块,并没有加入到Nginx...

    Nginx日志管理介绍

    Nginx日志描述 通过访问日志,你可以得到用户地域来源、跳转来源、使用终端、某个URL访问量等相关信息;通过错误日志,你可以得到系统某个服务或server的性能瓶颈等。因此,将日志好好利用,你可以得到很多有价值的...

    可自动按天分割日志的nginx (根据nginx源代码修改得来)

    将在 logs目录下生成类似 2014-01-21.access.log 的log文件,这个日期会根据服务器的时间变化) 配置可参照 nginx目录下的 conf/nginx.conf 文件进行log配置 源码留给有特殊需要的朋友自己编译。此源码就是修改后的...

    Centos7环境下Nginx版本升级方式及步骤

    此手册主要用于记录个人进行nginx升级的步骤和心得,介绍了2种升级方式。 YUM upgrade升级:本方式适用于使用rpm安装nginx的方式,优点是升级操作简单便捷,缺点是无法升级到指定版本,默认升级至YUM安装支持的...

Global site tag (gtag.js) - Google Analytics