Ubuntu nginx 1.6.0 服务器 nginx.conf等相关配置-阿里云开发者社区

开发者社区> 开发与运维> 正文
登录阅读全文

Ubuntu nginx 1.6.0 服务器 nginx.conf等相关配置

简介: 环境UBUNUT 14.04  nginx:nginx 1.6.0 内存:12G呆狐狸.风来了 等有空了再添加 注释 nginx.conf user www www; #启动进程,通常设置成和cpu的数量相等 worker_processes 4; #错误日志文件 error_log /www/wwwLogs/nginx_error.log; pid
环境UBUNUT 14.04 
nginx:nginx 1.6.0
内存:12G

呆狐狸.风来了
等有空了再添加 注释

nginx.conf

user  www www;  
#启动进程,通常设置成和cpu的数量相等  
worker_processes  4;  
#错误日志文件  
error_log  /www/wwwLogs/nginx_error.log;  
pid        /www/lanmps/nginx/logs/nginx.pid;  
worker_rlimit_nofile 5120;  
events {  
    use epoll;  
    #单个worker process进程的最大并发链接数  
    worker_connections  5120;  
}  
  
http {  
    include       mime.types;  
    default_type  application/octet-stream;  
    #charset utf-8;  
  
    server_names_hash_bucket_size 128;  
    client_header_buffer_size 32k;  
    large_client_header_buffers 4 64k;  
      
    client_max_body_size    8m;
	client_body_buffer_size  256k;
    client_header_timeout    3m;
    client_body_timeout      3m;
    #limit_conn_zone $binary_remote_addr zone=one:32k;
	#limit_zone  crawler  $binary_remote_addr  10m;
    #sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,对于普通应用
    sendfile        on;
	#开启目录列表访问,默认关闭
	#autoindex on;
    tcp_nopush     on;
	server_tokens off;
	server_name_in_redirect off;
    #连接超时时间
    keepalive_timeout  60;
    tcp_nodelay on;
	
	fastcgi_connect_timeout 300;
	fastcgi_send_timeout 300;
	fastcgi_read_timeout 300;
	fastcgi_buffer_size 64k;
	fastcgi_buffers 4 64k;
	fastcgi_busy_buffers_size 128k;
	fastcgi_temp_file_write_size 256k;
	fastcgi_store_access  user:rw  group:rw  all:r;
	#设定负载均衡的服务器列表
	include upstream.conf;
	
	gzip_static on;
	#开启gzip压缩
    gzip  on;
    gzip_min_length  1k;
    gzip_buffers     16 64k;
    gzip_http_version 1.1;
    gzip_comp_level 3;
    gzip_types       text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
	gzip_proxied        expired no-cache no-store private auth;
	gzip_disable        "MSIE [1-6]\.";

	#log_format  access '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" $http_user_agent $http_x_forwarded_for';
	#日志参数,方便mysql 直接导入
	log_format  access '$remote_addr | $remote_user | [$time_local] | "$request" | $status | $body_bytes_sent | "$http_referer" | "$http_user_agent" | $http_x_forwarded_for';
	#access_log  /www/wwwLogs/$server_name.log access;
	
    #include default.conf;
	#站点配置文件
    include vhost/*.conf;
}


upstream.conf

upstream bakend {
	ip_hash;
        #weigth参数表示权值,权值越高被分配到的几率越大
	server 127.0.0.1:9000 weight=1 max_fails=1 fail_timeout=0s;
	#server 127.0.0.1:9001 weight=1 max_fails=1 fail_timeout=0s;
}

fastcgi.conf

if ($request_filename ~* (.*)\.php) {
    set $php_url $1;
}
if (!-e $php_url.php) {
    return 403;
}
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
#fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
#不显示nginx版本号
fastcgi_param  SERVER_SOFTWARE    nginx;

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

fastcgi_param  HTTPS              $https if_not_empty;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

vhost/www.lanmps.com.conf

server
{
        #监听端口
	listen       80;
        #域名,多个用空格隔开
	server_name www.lanmps.com ;
	index index.html index.htm index.php;
	root  /www/wwwroot/www.lanmps.com;
        #设置所有图片过期时间为30天
	location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)(.*)
	{
		expires      30d;
	}
        #设置所有js,css文件过期时间为12小时
	location ~ .*\.(js|css)(.*)
	{
		expires      12h;
	}
        #php 文件处理
	location ~ [^/]\.php(/|$) {
		#fastcgi_pass   127.0.0.1:9000;
		#fastcgi_pass  unix:/tmp/php-cgi.sock;
		fastcgi_pass   bakend;
		fastcgi_index index.php;
		include fastcgi.conf;
	}
	include /www/wwwroot/www.lanmps.com/lanmps-*.conf;
	access_log  /www/wwwLogs/www.lanmps.com.log  access;
}
server
{
	listen       80;
	server_name lanmps.com ;
        #如果当前访问的域名是不带www的一级域名,则调整到带www的域名
	rewrite ^/(.*) http://www.lanmps.com/$1 permanent;
	access_log  /www/wwwLogs/lanmps.com.log  access;
}



版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

其他文章
最新文章
相关文章