Nginx 官方一个配置实例
[代码] nginx.conf
01 user www www;
02 worker_processes 5;
03 error_log logs/error.log;
04 pid logs/nginx.pid;
05 worker_rlimit_nofile 8192;
06
07 events {
08 worker_connections 4096;
09 }
10
11 http {
12 include conf/mime.types;
13 include /etc/nginx/proxy.conf;
14 include /etc/nginx/fastcgi.conf;
15
16 default_type application/octet-stream;
17 log_format main '$remote_addr - $remote_user [$time_local] $status '
18 '"$request" $body_bytes_sent "$http_referer" '
19 '"$http_user_agent" "$http_x_forwarded_for"';
20 access_log logs/access.log main;
21 sendfile on;
22 tcp_nopush on;
23 server_names_hash_bucket_size 128; # this seems to be required for some vhosts
24
25 server { # php/fastcgi
26 listen 80;
27 server_name domain1.com www.domain1.com;
28 access_log logs/domain1.access.log main;
29 root html;
30
31 location / {
32 index index.html index.htm index.php;
33 }
34
35 location ~ .php$ {
36 fastcgi_pass 127.0.0.1:1025;
37 }
38 }
39
40 server { # simple reverse-proxy
41 listen 80;
42 server_name domain2.com www.domain2.com;
43 access_log logs/domain2.access.log main;
44
45 # serve static files
46 location ~ ^/(images|javascript|js|css|flash|media|static)/ {
47 root /var/www/virtual/big.server.com/htdocs;
48 expires 30d;
49 }
50
51 # pass requests for dynamic content to rails/turbogears/zope, et al
52 location / {
53 proxy_pass http://127.0.0.1:8080;
54 }
55 }
56
57 upstream big_server_com {
58 server 127.0.0.3:8000 weight=5;
59 server 127.0.0.3:8001 weight=5;
60 server 192.168.0.1:8000;
61 server 192.168.0.1:8001;
62 }
63
64 server { # simple load balancing
65 listen 80;
66 server_name big.server.com;
67 access_log logs/big.server.access.log main;
68
69 location / {
70 proxy_pass http://big_server_com;
71 }
72 }
73 }
[代码] proxy_conf
view sourceprint?01 proxy_redirect off;
02 proxy_set_header Host $host;
03 proxy_set_header X-Real-IP $remote_addr;
04 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
05 client_max_body_size 10m;
06 client_body_buffer_size 128k;
07 proxy_connect_timeout 90;
08 proxy_send_timeout 90;
09 proxy_read_timeout 90;
10 proxy_buffers 32 4k;
[代码] fastcgi_conf
view sourceprint?01 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
02 fastcgi_param QUERY_STRING $query_string;
03 fastcgi_param REQUEST_METHOD $request_method;
04 fastcgi_param CONTENT_TYPE $content_type;
05 fastcgi_param CONTENT_LENGTH $content_length;
06 fastcgi_param SCRIPT_NAME $fastcgi_script_name;
07 fastcgi_param REQUEST_URI $request_uri;
08 fastcgi_param DOCUMENT_URI $document_uri;
09 fastcgi_param DOCUMENT_ROOT $document_root;
10 fastcgi_param SERVER_PROTOCOL $server_protocol;
11 fastcgi_param GATEWAY_INTERFACE CGI/1.1;
12 fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
13 fastcgi_param REMOTE_ADDR $remote_addr;
14 fastcgi_param REMOTE_PORT $remote_port;
15 fastcgi_param SERVER_ADDR $server_addr;
16 fastcgi_param SERVER_PORT $server_port;
17 fastcgi_param SERVER_NAME $server_name;
18
19 fastcgi_index index.php;
20
21 fastcgi_param REDIRECT_STATUS 200;
[代码] mime_types
view sourceprint?01 types {
02 text/html html htm shtml;
03 text/css css;
04 text/xml xml rss;
05 image/gif gif;
06 image/jpeg jpeg jpg;
07 application/x-javascript js;
08 text/plain txt;
09 text/x-component htc;
10 text/mathml mml;
11 image/png png;
12 image/x-icon ico;
13 image/x-jng jng;
14 image/vnd.wap.wbmp wbmp;
15 application/java-archive jar war ear;
16 application/mac-binhex40 hqx;
17 application/pdf pdf;
18 application/x-cocoa cco;
19 application/x-java-archive-diff jardiff;
20 application/x-java-jnlp-file jnlp;
21 application/x-makeself run;
22 application/x-perl pl pm;
23 application/x-pilot prc pdb;
24 application/x-rar-compressed rar;
25 application/x-redhat-package-manager rpm;
26 application/x-sea sea;
27 application/x-shockwave-flash swf;
28 application/x-stuffit sit;
29 application/x-tcl tcl tk;
30 application/x-x509-ca-cert der pem crt;
31 application/x-xpinstall xpi;
32 application/zip zip;
33 application/octet-stream deb;
34 application/octet-stream bin exe dll;
35 application/octet-stream dmg;
36 application/octet-stream eot;
37 application/octet-stream iso img;
38 application/octet-stream msi msp msm;
39 audio/mpeg mp3;
40 audio/x-realaudio ra;
41 video/mpeg mpeg mpg;
42 video/quicktime mov;
43 video/x-flv flv;
44 video/x-msvideo avi;
45 video/x-ms-wmv wmv;
46 video/x-ms-asf asx asf;
47 video/x-mng mng;
48 }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论