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