作者:Victoria625_176 | 来源:互联网 | 2017-11-02 21:50
Nginx:0.8.151、安装Nginx所需的pcre库:#cdusrlocalsrctarbag#tarzxvfpcre-7.9.tar.gz-C..software#cd..softwarepcre-7.9#.configure#makemakeinstall#cdhttp:www.linuxidc.comtarbag2、安装Nginx#tarzxvfnginx-0.8.15.tar.gz
Nginx :0.8.15
1、安装Nginx所需的pcre库:
- #cd /usr/local/src/tarbag
- #tar zxvf pcre-7.9.tar.gz -C ../software
- #cd ../software/pcre-7.9/
- #./configure
- #make && make install
- #cd http://www.linuxidc.com/tarbag
2、安装Nginx
- #tar zxvf nginx-0.8.15.tar.gz -C ../software
- #cd ../software/nginx-0.8.15/
- #./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module--with-http_ssl_module
- #make && make install
- #cd http://www.linuxidc.com/tarbag
3、创建Nginx日志目录
- mkdir -p /opt/www/nginx/logs
- chmod +w /www/nginx/logs
- chown -R nobody:nobody /www/nginx/logs
4、创建Nginx配置文件
在/usr/local/nginx/conf/目录中创建nginx.conf文件:
- rm -f /usr/local/nginx/conf/nginx.conf
- vi /usr/local/nginx/conf/nginx.conf
- user nobody nobody;
- worker_processes 8;
- error_log /opt/www/nginx/logs/nginx_error.log crit;
- pid /usr/local/nginx/nginx.pid;
- #Specifies the value for maximum file descriptors that can be opened by this process.worker_rlimit_nofile 65535;
- events
- {
- use epoll;
- worker_connections 65535;
- }
- http
- {
- include mime.types;
- default_type application/octet-stream;
- #charset gb2312;
- server_names_hash_bucket_size 128;
- client_header_buffer_size 32k;
- large_client_header_buffers 4 32k;
- client_max_body_size 8m;
- sendfile on;
- tcp_nopush on;
- keepalive_timeout 60;
- tcp_nodelay on;
- gzip on;
- gzip_min_length 1k;
- gzip_buffers 4 16k;
- gzip_http_version 1.0;
- gzip_comp_level 2;
- gzip_types text/plain application/x-Javascript text/css application/xml;
- gzip_vary on;
- log_format access \'$remote_addr - $remote_user [$time_local] \'
- \"$request\" $status $bytes_sent \'
- \'\"$http_referer\" \"$http_user_agent\" \'
- \"$gzip_ratio\"\';
- log_format wwwlogs \'$remote_addr - $remote_user [$time_local] \'
- \'\"$request\" $status $bytes_sent \'
- \'\"$http_referer\" \"$http_user_agent\" \'
- \'\"$http_range\" \"$sent_http_content_range\"\';
- include vhosts.conf
- }
在/usr/local/nginx/conf/目录中创建vhosts.conf文件:
- vi /usr/local/nginx/conf/vhosts.conf
- #limit_zone crawler $binary_remote_addr 10m;
- server
- {
- listen 80;
- server_name www.hsf.com;
- index index.html index.htm index.php;
- root /www/blog;
- #limit_conn crawler 20;
- access_log /opt/www/nginx/logs/access.log access;
- }
- server
- {
- listen 80;
- server_name www.hsf.com;
- index index.html index.htm index.php;
- root /www/www;
- access_log /www/nginx/wwwlogs.log wwwlogs;
- }
- server
- {
- listen 80;
- server_name status.www.hsf.com;
- location /
- {
- stub_status on;
- access_log off;
- }
- }
5、启动Nginx
- ulimit -SHn 65535
- /usr/local/nginx/sbin/nginx
优化Linux内核参数
- vi /etc/sysctl.conf
在末尾增加以下内容:
- # Add
- net.ipv4.tcp_max_syn_backlog = 65536
- net.core.netdev_max_backlog = 32768
- net.core.somaxconn = 32768
- net.core.wmem_default = 8388608