-
Hey! Linux分类的最新文章
-
目录
-
Nginx 是一个高性能的 HTTP 和 反向代理服务器,也是一个 IMAP/POP3/SMTP 代理服务器。Nginx 编译安装比较简单,难点在于配置
优点:
支持高达 50,000 个并发连接数的响应,Nginx为我们选择了 epoll and kqueue作为开发模型。
Nginx作为负载均衡服务器:Nginx 既可以在内部直接支持 Rails 和 PHP 程序对外进行服务,也可 以支持作为 HTTP代理服务器对外进行服务。Nginx采用C进行编写,不论是系统资源开销还是CPU使用效率都比 Perlbal 要好很多。
作为邮件代理服务器:Nginx 同时也是一个非常优秀的邮件代理服务器
Nginx 是一个安装非常的简单,配置文件非常简洁(还能够支持perl语法),Bugs非常少的服务器:Nginx 启动特别容易,并且几乎可以做到7*24不间断运行,即使运行数个月也不需要重新启动。你还能够不间断服务的情况下进行软件版本的升级。
step 1 模块依赖性
yum -y install gcc openssl-devel pcre-devel zlib-devel
step 2 编译安装
groupadd nginx useradd -g nginx -s /bin/false -M nginx tar -zxf nginx-1.8.0.tar.gz cd nginx-1.8.0 ./configure \ --prefix=/usr \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/var/run/nginx/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-http_flv_module \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --http-client-body-temp-path=/var/tmp/nginx/client/ \ --http-proxy-temp-path=/var/tmp/nginx/proxy/ \ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ make && make install makdir -p /var/log/nginx
step 3 常规配置
user nginx; worker_processes 12; worker_cpu_affinity 000000000001 000000000010 000000000100 000000001000 000000010000 000000100000 000001000000 000010000000 000100000000 001000000000 010000000000 100000000000; worker_rlimit_nofile 102400; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 102400; multi_accept on; use epoll; } http { include /etc/nginx/mime.types; default_type application/octet-stream; server_names_hash_bucket_size 128; client_header_buffer_size 16k; large_client_header_buffers 4 16k; client_max_body_size 50m; sendfile on; access_log off; tcp_nopush on; tcp_nodelay on; server_tokens off; keepalive_timeout 60 60; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 8 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; fastcgi_intercept_errors on; gzip on; gzip_min_length 1000; gzip_proxied expired no-cache no-store private auth; gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml application/rss+xml application/xhtml+xml application/atom_xml; gzip_disable "MSIE [1-6].(?!.*SV1)"; log_format access '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $http_x_forwarded_for'; include /etc/nginx/conf.d/*.conf; }
upstream www.cloudray.cn { server 192.168.10.144:80 weight=10 max_fails=2 fail_timeout=5s; server 192.168.10.188:80 weight=10 max_fails=2 fail_timeout=5s; keepalive 60; } server { listen 80; server_name www.cloudray.cn; #charset koi8-r; #access_log /var/log/nginx/www.cloudray.cn.log main; location / { proxy_pass http://www.cloudray.cn; proxy_http_version 1.1; proxy_redirect off; proxy_set_header Connection ""; }
server { listen 80; #listen end server_name lelady.cn www.cloudray.cn; #server_name end index index.html index.htm index.php; #index end set $subdomain ''; root /home/wwwroot/lnmp/domain/www.cloudray.cn/web$subdomain; #error_page location ~ /ErrorPages/(400|401|403|404|405|502|503)\.html$ { root /home/wwwroot/lnmp/domain/www.cloudray.cn/web; } location ~ .*\.php$ { fastcgi_pass unix:/var/run/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_param DOCUMENT_ROOT /home/wwwroot/lnmp/domain/www.cloudray.cn/web$subdomain; fastcgi_param SCRIPT_FILENAME /home/wwwroot/lnmp/domain/www.cloudray.cn/web$subdomain$fastcgi_script_name; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp3|wma)$ { expires 30d; valid_referers none blocked www.cloudray.cn cloudray.cn; if ($invalid_referer) { return 502; } } location ~ .*\.(js|css)$ { expires 12h; } #access_log /home/wwwroot/lnmp/logs/www.cloudray.cn-access.log combined; #access_log end access_log off; error_log /home/wwwroot/lnmp/logs/www.cloudray.cn-error.log crit; #error_log end }
0
收藏
Ctrl+Enter 发布
发布
取消