Nginx -- nginx. conf 프로필 상세 설명

41721 단어 nginx
Nginx 서버 설정, nginx. conf 파일 코드 상세 설명, 서로 다른 건물의 블 로그 와 결합 하여 얻 을 수 있 습 니 다:
  1 #             

  2 

  3 #  Nginx         

  4 #user  nobody;

  5 

  6 #nginx   

  7 #  NginX   SLL  gzip, cpu      ,         cpu

  8 #      cpu    

  9 worker_processes  1;

 10 

 11 #            

 12 worker_rlimit_nofile 65535;S

 13 

 14 #error_log  x:/xxxxx/xxxx/log/error.log;

 15 #error_log  logs/error.log  notice;

 16 #error_log  logs/error.log  info;

 17 

 18 #    

 19 pid        logs/nginx.pid;

 20 

 21 #Nginx     ,    Nginx      ,       ,    。

 22 events {

 23     #    worker process          

 24     #       65535 

 25     worker_connections  1024;

 26     #woker_connections 65535;

 27     #       worker_processes   worker_connections    

 28     #   max_clients = worker_processes * worker_connections

 29     #             ,max_clients = worker_processes * worker_connections / 4     

 30     #             4,         

 31     #       ,      Nginx Server           :4 * 8000 = 32000

 32     # worker_connections              

 33     #      IO  ,max_clients                 

 34     #                      ,  1GB                 10   

 35     #      360M   VPS             :

 36     # $ cat /proc/sys/fs/file-max

 37     #    34336

 38     # 32000 < 34336,                      ,                 

 39     #   ,worker_connections       worker_processes                            

 40     #                        

 41     #              CPU       

 42     #   ,                  ,                     。

 43     # ulimit -SHn 65535

 44 }

 45 

 46 

 47 

 48 

 49 #Nginx HTTP    ,  http   

 50 http {

 51     #             

 52     include       mime.types;

 53     #      

 54     default_type  application/octet-stream;

 55     #    

 56     #charset utf-8; 

 57 

 58     #  Nginx   

 59     #server_tokens off

 60 

 61    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

 62                       '$status $body_bytes_sent "$http_referer" '

 63                       '"$http_user_agent" "$http_x_forwarded_for"';

 64 

 65     #access_log  x:/xxxx/xxxx/log/access.log  main;

 66     #    

 67     #access_log off;

 68     #          ,sendfile    nginx    sendfile       

 69     #         on,

 70     #             IO     ,    off,        I/O    ,       。

 71     #  :              off。

 72     sendfile        on;

 73     #tcp_nopush     on;

 74 

 75     #keepalive_timeout  0;

 76     keepalive_timeout  60;

 77 

 78 

 79     #  gzip    

 80     #gzip  on;

 81     #            ,     。

 82     #gzip_min_length 1000;

 83     #                    Gzip    

 84     # expired---  Expires header    ,      

 85     # auth -----     Authorization header,     

 86     #gzip_proxied expired no-cache no-store private auth;

 87     #gzip_types text/plain application/xml;

 88     #gzip_disable "MSIE [1-6].";

 89 

 90     #              。     413  

 91     client_max_body_size       16m;

 92     #

 93     #

 94     #    8k/16k

 95     #

 96     client_body_buffer_size    256k;

 97     proxy_temp_file_write_size 128k;

 98     proxy_temp_path  x:/xxx/xxxxx/public;

 99     #levels      

100     #keys_zone             

101     #inactive                  1 

102     #max_size      

103     #proxy_cache_path x:/xxxx/xxx/cache levels=1:2 keys_zone=cache_one:256m inactive=2d max_size=300m;

104 

105 

106 

107 

108     upstream mywebapp_thin 

109     {

110     #             ,        IP           。 

111     #IPv4          IPv6     ,          key。 

112     #                    ,          。

113     #               ,                 ,

114     #

115     #        ,                 IP     upstream  server  。

116     #                ip        

117     #                           ,              ,

118     #

119     #                      

120     #        ,        。

121     ip_hash;

122     #upstream     ,weight   ,            。

123     #weigth      ,             。

124     #        ,  ip   down

125     #backup    

126     server 127.0.0.1:3000;

127     server 127.0.0.1:3001 down;

128     }

129 

130 

131 

132     #        

133     server {

134         #    

135         listen       80 default_server;

136         #     localhost  

137         #

138         #    HTTP      (Host header) Nginx       Server{...}    

139         #           server  ——。

140         #

141         #1.   ,    

142         #2.            ,  :*.exmple.com

143         #3.            ,  :www.example.*

144         #4.          。

145         server_name  localhost;

146 

147         #    

148         #charset koi8-r;

149 

150         #rewrite_log on;

151 

152         #            

153         #access_log  logs/host.access.log  main;

154         #access_log  x:/xxx/xxx/log/host.access.log;

155 

156         root   x:/xxx/xxx/public;

157 

158 

159 

160         #        

161         #location ~* ^/(images|javascripts|stylesheets|img)/ 

162         #location ~* .(gif|jpg|jpeg|png|bmp|swf)$ 

163         #{

164         #    root   x:/xx/xxx/public;

165         #    access_log    off;

166         #    log_not_found off;

167         #    expires       max;

168 

169             #  key hash,  KEY  

170         #    proxy_cache_key      $host$uri$is_args$args;

171             # keys_zone      

172         #    proxy_cache         cache_one;

173             #          

174         #    proxy_cache_valid    200 302 7d;

175             #         

176         #    proxy_cache_valid    301 3d;

177         #    proxy_cache_valid    any 1m;

178 

179         #   if (!-f $request_filename) {

180         #    proxy_pass http://mywebapp_thin;

181         #    break;

182         #    } 

183         #break;

184         #}

185 

186         #    URI         

187         #                       

188         #

189         # “~”        

190         # “~*”       

191         #          ,        ,     

192         #    ,  "/"       

193         location / {

194             #             

195             root   x:/xxx/xxx/public;

196             #           

197             index  index.html index.htm;

198             if (!-f $request_filename) {

199             proxy_pass http://mywebapp_thin;

200              break;

201             } 

202             proxy_redirect off;

203             proxy_set_header X-Real-IP $remote_addr;

204             #   Web       X-Forwarded-For      IP

205             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

206             #            ,  。

207             proxy_set_header Host $host;

208             #                

209             client_max_body_size 10m; 

210             #

211             client_body_buffer_size 128k; 

212             #nginx            (      )

213             proxy_connect_timeout 90; 

214             #           (      )

215             proxy_send_timeout 90;

216             #     ,         (      ) 

217             proxy_read_timeout 90; 

218             #       (nginx)             

219             proxy_buffer_size 4k; 

220             #proxy_buffers   ,     32k     

221             proxy_buffers 4 32k;

222             #     ,               。 

223             proxy_buffering on;

224             #        (proxy_buffers*2)

225             proxy_busy_buffers_size 64k; 

226             #         ,     ,  upstream    

227             proxy_temp_file_write_size 64k;

228 

229               #  key hash,  KEY  

230         #    proxy_cache_key      $host$uri$is_args$args;

231             # keys_zone      

232         #    proxy_cache         cache_one;

233             #          

234         #    proxy_cache_valid    200 302 7d;

235             #         

236         #    proxy_cache_valid    301 3d;

237         #    proxy_cache_valid    any 1m;

238         }

239 

240 

241         #    uri,              

242         #error_page  404              /404.html;

243 

244         # redirect server error pages to the static page /50x.html

245         #

246         #         

247         error_page   500 502 503 504  /50x.html;

248         location = /50x.html {

249             root   html;

250         }

251 

252         # proxy the PHP scripts to Apache listening on 127.0.0.1:80

253         #

254         #location ~ .php$ {

255         #    proxy_pass   http://127.0.0.1;

256         #}

257 

258         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

259         #

260         #location ~ .php$ {

261         #    root           html;

262         #    fastcgi_pass   127.0.0.1:9000;

263         #    fastcgi_index  index.php;

264         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

265         #    include        fastcgi_params;

266         #}

267 

268         # deny access to .htaccess files, if Apache's document root

269         # concurs with nginx's one

270         #

271         #location ~ /.ht {

272         #    deny  all;

273         #}

274 

275         #        

276         #location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$

277         #{

278         #    expires 10d;

279         #}  

280         #JS CSS      

281         #location ~ .*.(js|css)?$

282         #{

283         #    expires 1h;

284         #}

285 

286         #FastCGI              :      ,      。

287         fastcgi_connect_timeout 300;

288         fastcgi_send_timeout 300;

289         fastcgi_read_timeout 300;

290         fastcgi_buffer_size 64k;

291         fastcgi_buffers 4 64k;

292         fastcgi_busy_buffers_size 128k;

293         fastcgi_temp_file_write_size 128k;

294     }

295 

296 

297     # another virtual host using mix of IP-, name-, and port-based configuration

298     #

299     #server {

300     #    listen       8000;

301     #    listen       somename:8080;

302     #    server_name  somename  alias  another.alias;

303 

304     #    location / {

305     #        root   html;

306     #        index  index.html index.htm;

307     #    }

308     #}

309 

310 

311     # HTTPS server

312     #

313     #server {

314     #    listen       443 ssl;

315     #    server_name  localhost;

316 

317     #    ssl_certificate      cert.pem;

318     #    ssl_certificate_key  cert.key;

319 

320     #    ssl_session_cache    shared:SSL:1m;

321     #    ssl_session_timeout  5m;

322 

323     #    ssl_ciphers  HIGH:!aNULL:!MD5;

324     #    ssl_prefer_server_ciphers  on;

325 

326     #    location / {

327     #        root   html;

328     #        index  index.html index.htm;

329     #    }

330     #}

331 

332 }

About this: http://www.ha97.com/5194.html

좋은 웹페이지 즐겨찾기