| 
                           由于涉及到h5与后端交互,跨域问题,所以公司的开放测试服务器让我们自己搞nginx。顺便提升一下nginx的实践。 
 nginx的安装,没什么难度了,百度一堆,如果源码安装就一步步来吧。(最简单的方式:yum install nginx (centos),apt-get install nginx(ubuntu)) nginx.conf,作为最外层的配置文件,主要设置一些基础的配置就好了,如内存配置,日志格式配置,线程配置等,最后使用一个include conf.d/* 将其他配置文件包含进来即可。 
【nginx.conf 基础配置】 
error_log  /data/var/log/nginx/<span style="color: #000000">error.log debug;
error_log  logs/<span style="color: #000000">error.log  notice;
error_log  logs/error.log  <span style="color: #0000ff">info<span style="color: #000000">;
pid        logs/<span style="color: #000000">nginx.pid;
events { 
worker_connections  <span style="color: #800080">1024<span style="color: #000000">; 
} 
load modules compiled as Dynamic Shared Object (DSO)
dso {
load ngx_http_fastcgi_module.so;
load ngx_http_rewrite_module.so;
}
http { 
include       mime.types; 
default_type  application/octet-<span style="color: #000000">stream; 
autoindex off; 
server_tokens off; 
server_names_hash_bucket_size </span><span style="color: #800080">128</span><span style="color: #000000">;
client_header_buffer_size 32k;
large_client_header_buffers </span><span style="color: #800080">4</span><span style="color: #000000"> 32k;
client_max_body_size 20m;
client_body_buffer_size 256k;
sendfile on;
tcp_nopush     on;
keepalive_timeout </span><span style="color: #800080">60</span><span style="color: #000000">;
tcp_nodelay on;
fastcgi_connect_timeout </span><span style="color: #800080">300</span><span style="color: #000000">;
fastcgi_send_timeout </span><span style="color: #800080">300</span><span style="color: #000000">;
fastcgi_read_timeout </span><span style="color: #800080">300</span><span style="color: #000000">;
fastcgi_buffer_size 128k;
fastcgi_buffers </span><span style="color: #800080">32</span><span style="color: #000000"> 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
</span><span style="color: #0000ff">gzip</span><span style="color: #000000">  on;
gzip_disable </span><span style="color: #800000">"</span><span style="color: #800000">msie6</span><span style="color: #800000">"</span><span style="color: #000000">;
gzip_vary on;
gzip_comp_level </span><span style="color: #800080">2</span><span style="color: #000000">;
gzip_min_length 1k;
gzip_buffers </span><span style="color: #800080">4</span><span style="color: #000000"> 16k;
gzip_http_version </span><span style="color: #800080">1.1</span><span style="color: #000000">;
gzip_types text</span>/plain application/x-javascript text/css application/xml application/<span style="color: #000000">javascript;
log_format main </span><span style="color: #800000">'</span><span style="color: #800000">$request_time $upstream_response_time $remote_addr - $upstream_addr [$time_local] </span><span style="color: #800000">'</span>
<span style="color: #800000">'</span><span style="color: #800000">"$host" "$request" $status $bytes_sent </span><span style="color: #800000">'</span>
<span style="color: #800000">'</span><span style="color: #800000">"$http_referer" "$http_user_agent" "$gzip_ratio" "$http_x_forwarded_for" - "$server_addr" </span><span style="color: #800000">'</span><span style="color: #000000">;
access_log </span>/data/var/log/nginx/<span style="color: #000000">access.log main;
include conf.d</span><span style="color: #008000">/*</span><span style="color: #008000">.conf; 
} 
【conf.d/*,具体的域名配置,http://】 
.:.:.:.:server { 
listen <span style="color: #800080">80<span style="color: #000000">; 
server_name 3ctest.x123.com; 
location /<span style="color: #000000"> { 
proxy_pass http:<span style="color: #008000">//<span style="color: #008000">3ctest_x123_com; 
<span style="color: #000000">                proxy_set_header Host $host; 
proxy_redirect off; 
proxy_set_header X-Real-<span style="color: #000000">IP $remote_addr; 
proxy_set_header X-Forwarded-<span style="color: #000000">For $proxy_add_x_forwarded_for; 
proxy_connect_timeout <span style="color: #800080">60<span style="color: #000000">; 
proxy_read_timeout <span style="color: #800080">600<span style="color: #000000">; 
proxy_send_timeout <span style="color: #800080">600<span style="color: #000000">; 
} 
}
server { 
listen <span style="color: #800080">80<span style="color: #000000">; 
server_name mytest.x123.com; 
location /<span style="color: #000000"> { 
proxy_pass http:<span style="color: #008000">//<span style="color: #008000">mytest_x123_com; 
<span style="color: #000000">                proxy_set_header Host $host; 
proxy_redirect off; 
proxy_set_header X-Real-<span style="color: #000000">IP $remote_addr; 
proxy_set_header X-Forwarded-<span style="color: #000000">For $proxy_add_x_forwarded_for; 
proxy_connect_timeout <span style="color: #800080">60<span style="color: #000000">; 
proxy_read_timeout <span style="color: #800080">600<span style="color: #000000">; 
proxy_send_timeout <span style="color: #800080">600<span style="color: #000000">; 
} 
} 
server { 
listen <span style="color: #800080">80<span style="color: #000000">; 
server_name 3capi.x123.com; 
location /<span style="color: #000000"> { 
proxy_pass http:<span style="color: #008000">//<span style="color: #008000">3capi_x123_com; 
<span style="color: #000000">                proxy_set_header Host $host; 
proxy_redirect off; 
proxy_set_header X-Real-<span style="color: #000000">IP $remote_addr; 
proxy_set_header X-Forwarded-<span style="color: #000000">For $proxy_add_x_forwarded_for; 
proxy_connect_timeout <span style="color: #800080">60<span style="color: #000000">; 
proxy_read_timeout <span style="color: #800080">600<span style="color: #000000">; 
proxy_send_timeout <span style="color: #800080">600<span style="color: #000000">; 
} 
} 
server { 
listen <span style="color: #800080">80<span style="color: #000000">; 
server_name yhapi.x123.com; 
location /<span style="color: #000000"> { 
proxy_pass http:<span style="color: #008000">//<span style="color: #008000">yhapi_x123_com; 
<span style="color: #000000">                proxy_set_header Host $host; 
proxy_redirect off; 
proxy_set_header X-Real-<span style="color: #000000">IP $remote_addr; 
proxy_set_header X-Forwarded-<span style="color: #000000">For $proxy_add_x_forwarded_for; 
proxy_connect_timeout <span style="color: #800080">60<span style="color: #000000">; 
proxy_read_timeout <span style="color: #800080">600<span style="color: #000000">; 
proxy_send_timeout <span style="color: #800080">600<span style="color: #000000">; 
} 
} 
server { 
listen <span style="color: #800080">80<span style="color: #000000">; 
server_name <span style="color: #800080">192.168.<span style="color: #800080">1.22<span style="color: #000000">; 
location /<span style="color: #000000"> { 
proxy_pass http:<span style="color: #008000">//<span style="color: #008000">192.168.1.22; 
<span style="color: #000000">                proxy_set_header Host $host; 
proxy_redirect off; 
proxy_set_header X-Real-<span style="color: #000000">IP $remote_addr; 
proxy_set_header X-Forwarded-<span style="color: #000000">For $proxy_add_x_forwarded_for; 
proxy_connect_timeout <span style="color: #800080">60<span style="color: #000000">; 
proxy_read_timeout <span style="color: #800080">600<span style="color: #000000">; 
proxy_send_timeout <span style="color: #800080">600<span style="color: #000000">; 
} 
} 
                        (编辑:莱芜站长网) 
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! 
                     |