1. #user nobody;
    2. #开启进程数 <=CPU数
    3. worker_processes 1;
    4. #错误日志保存位置
    5. #error_log logs/error.log;
    6. #error_log logs/error.log notice;
    7. #error_log logs/error.log info;
    8. #进程号保存文件
    9. #pid logs/nginx.pid;
    10. #每个进程最大连接数(最大连接=连接数x进程数)每个worker允许同时产生多少个链接,默认1024
    11. events {
    12. worker_connections 1024;
    13. }
    14. http {
    15. #文件扩展名与文件类型映射表
    16. include mime.types;
    17. #默认文件类型
    18. default_type application/octet-stream;
    19. #日志文件输出格式 这个位置相于全局设置
    20. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    21. '$status $body_bytes_sent "$http_referer" '
    22. '"$http_user_agent" "$http_x_forwarded_for"';
    23. #请求日志保存位置
    24. #access_log logs/access.log main;
    25. #打开发送文件
    26. sendfile on;
    27. #tcp_nopush on;
    28. #keepalive_timeout 0;
    29. #连接超时时间
    30. keepalive_timeout 65;
    31. #打开gzip压缩
    32. #gzip on;
    33. #设定请求缓冲
    34. #client_header_buffer_size 1k;
    35. #large_client_header_buffers 4 4k;
    36. #设定负载均衡的服务器列表
    37. #upstream myproject {
    38. #weigth参数表示权值,权值越高被分配到的几率越大
    39. #max_fails 当有#max_fails个请求失败,就表示后端的服务器不可用,默认为1,将其设置为0可以关闭检查
    40. #fail_timeout 在以后的#fail_timeout时间内nginx不会再把请求发往已检查出标记为不可用的服务器
    41. #}
    42. #webapp
    43. #upstream myapp {
    44. # server 192.168.122.133:8080 weight=1 max_fails=2 fail_timeout=30s;
    45. # server 192.168.122.134:8080 weight=1 max_fails=2 fail_timeout=30s;
    46. #}
    47. #配置虚拟主机,基于域名、ip和端口
    48. server {
    49. #监听端口
    50. listen 80;
    51. #监听域名
    52. server_name localhost;
    53. #charset koi8-r;
    54. #nginx访问日志放在logs/host.access.log下,并且使用main格式(还可以自定义格式)
    55. #access_log logs/host.access.log main;
    56. #返回的相应文件地址
    57. location / {
    58. #设置客户端真实ip地址
    59. #proxy_set_header X-real-ip $remote_addr;
    60. #负载均衡反向代理
    61. #proxy_pass http://myapp;
    62. #返回根路径地址(相对路径:相对于/usr/local/nginx/)
    63. root html;
    64. #默认访问文件
    65. index index.html index.htm;
    66. }
    67. #配置反向代理tomcat服务器:拦截.jsp结尾的请求转向到tomcat
    68. #location ~ \.jsp$ {
    69. # proxy_pass http://192.168.122.133:8080;
    70. #}
    71. #error_page 404 /404.html;
    72. # redirect server error pages to the static page /50x.html
    73. #
    74. #错误页面及其返回地址
    75. error_page 500 502 503 504 /50x.html;
    76. location = /50x.html {
    77. root html;
    78. }
    79. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    80. #
    81. #location ~ \.php$ {
    82. # proxy_pass http://127.0.0.1;
    83. #}
    84. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    85. #
    86. #location ~ \.php$ {
    87. # root html;
    88. # fastcgi_pass 127.0.0.1:9000;
    89. # fastcgi_index index.php;
    90. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    91. # include fastcgi_params;
    92. #}
    93. # deny access to .htaccess files, if Apache's document root
    94. # concurs with nginx's one
    95. #
    96. #location ~ /\.ht {
    97. # deny all;
    98. #}
    99. }
    100. #虚拟主机配置:
    101. server {
    102. listen 1234;
    103. server_name wolfcode.cn;
    104. location / {
    105. #正则表达式匹配uri方式:在/usr/local/nginx/wolfcode.cn下 建立一个test123.html 然后使用正则匹配
    106. #location ~ test {
    107. ## 重写语法:if return (条件 = ~ ~*)
    108. #if ($remote_addr = 192.168.122.1) {
    109. # return 401;
    110. #}
    111. #if ($http_user_agent ~* firefox) {
    112. # rewrite ^.*$ /firefox.html;
    113. # break;
    114. #}
    115. root wolfcode.cn;
    116. index index.html;
    117. }
    118. #location /goods {
    119. # rewrite "goods-(\d{1,5})\.html" /goods-ctrl.html;
    120. # root wolfcode.cn;
    121. # index index.html;
    122. #}
    123. #配置访问日志
    124. access_log logs/wolfcode.cn.access.log main;
    125. }
    126. # another virtual host using mix of IP-, name-, and port-based configuration
    127. #
    128. #server {
    129. # listen 8000;
    130. # listen somename:8080;
    131. # server_name somename alias another.alias;
    132. # location / {
    133. # root html;
    134. # index index.html index.htm;
    135. # }
    136. #}
    137. # HTTPS server
    138. #
    139. #server {
    140. # listen 443 ssl;
    141. # server_name localhost;
    142. # ssl_certificate cert.pem;
    143. # ssl_certificate_key cert.key;
    144. # ssl_session_cache shared:SSL:1m;
    145. # ssl_session_timeout 5m;
    146. # ssl_ciphers HIGH:!aNULL:!MD5;
    147. # ssl_prefer_server_ciphers on;
    148. # location / {
    149. # root html;
    150. # index index.html index.htm;
    151. # }
    152. #}
    153. }