后端基础知识

2,212
-1

Published on

Published in: Technology
0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,212
On Slideshare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
23
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide

后端基础知识

  1. 1. ••• http://panweizeng.com
  2. 2. • http://meituan.com
  3. 3. • http://meituan.com• hosts
  4. 4. • http://meituan.com• hosts• localhost 127.0.0.1
  5. 5. • /etc/nsswitch.conf• /etc/hosts• /etc/resolv.conf
  6. 6. Mail Client Web Browsercache 1-30minsClients Programs Your Computer
  7. 7. Mail Client Web Browser hostscache 1-30minsClients Programs Your Computer
  8. 8. Mail Client Web Browser hosts DNS Resolvercache 1-30mins local cacheClients Programs Your Computer
  9. 9. Mail Client Web Browser hosts DNS Resolvercache 1-30mins local cacheClients Programs Your Computer
  10. 10. Your Computer
  11. 11. Local Name Server / Your ISP 1 Your Computer
  12. 12. Local Name Server / Your ISP Root Name Server 2 1 Your Computer
  13. 13. Local Name Server / Your ISP Root Name Server 2 1 Your Computer
  14. 14. Local Name Server / Your ISP Root Name Server 2 3 Com Name Server 1 Your Computer
  15. 15. Local Name Server / Your ISP Root Name Server 2 3 Com Name Server 1 Your Computer
  16. 16. Local Name Server / Your ISP Root Name Server 2 3 Com Name Server 4 Meituan Name Server 1 Your Computer
  17. 17. Local Name Server / Your ISP Root Name Server 2 3 Com Name Server 4 Meituan Name Server 1 Your Computer
  18. 18. Local Name Server / Your ISP Root Name Server 2 3 Com Name Server 4 Meituan Name Server 1 5 Your Computer
  19. 19. Local Name Server / Your ISP Root Name Server 2 3 Com Name Server 4 Meituan Name Server 1 5 6 Your Computer Meituan Web Server
  20. 20. • meituan.com• www.meituan.com
  21. 21. • dig meituan.com• dig +trace meituan.com• dig www.meituan.com• dig s0.meituan.com
  22. 22. HTTP• Hypertext Transfer Protocol
  23. 23. HTTP• Hypertext Transfer Protocol• HTTP
  24. 24. HTTP• Hypertext Transfer Protocol• HTTP
  25. 25. client server
  26. 26. requestclient server
  27. 27. requestclient server response
  28. 28. • GET /path/to/file/index.html HTTP/1.0
  29. 29. • HTTP/1.0 200 OK
  30. 30. • 404 Not Found• 500 Server Error
  31. 31. • 301 Moved Permanently• 302 Moved Temporarily• 304 Not Modified• 401 Unauthorized• 403 Forbidden• 502 Bad Gateway
  32. 32. Request Headers• Host: www.meituan.com• User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
  33. 33. AJAX• X-Requested-With: XMLHttpRequest
  34. 34. Response Headers• Server: nginx• Date: Mon, 20 Jun 2011 09:12:11 GMT• Content-Type: application/json; charset=utf-8;• Content-Length: 138
  35. 35. •• cookie• session
  36. 36.
  37. 37. Apache• HTTP Server
  38. 38. • sudo /etc/init.d/httpd start• sudo /etc/init.d/httpd stop• sudo /etc/init.d/httpd restart/graceful
  39. 39. Mac• sudo apachectl start
  40. 40. • /etc/httpd/conf/http.conf• /etc/http/conf/vm/*
  41. 41. • ServerRoot "/etc/httpd"• DocumentRoot "/opt/www/webroot"• Listen 80
  42. 42. • User apache• Group apache• LoadModule php5_module /usr/lib64/ httpd/modules/libphp5.so
  43. 43. • DirectoryIndex index.php index.html• AccessFileName .htaccess• ErrorLog /opt/logs/error_log• ErrorDocument 404 /not-found.html
  44. 44. <Directory /> Options FollowSymLinks Indexes AllowOverride None</Directory>
  45. 45. <VirtualHost *:80> ServerName www.xpmt.com ServerAlias *.xpmt.com DocumentRoot /home/panweizeng/mt/webroot RewriteEngine on RewriteRule ^/(static/.*)$ /$1 [L] RewriteRule ^/(.*)$ /index.php [L]</VirtualHost>
  46. 46. <VirtualHost *:80> ServerName xpmt.com RewriteEngine On RewriteRule ^/(.*)$ http://www.xpmt.com/$1 [L,R]</VirtualHost>
  47. 47. Nginx• HTTP server• load balancer
  48. 48. apache
  49. 49. nginxngnix
  50. 50. ngnix nginxapache apache ... apache apache
  51. 51.
  52. 52. PHP Framework••
  53. 53. where to start• apache config• webroot/index.php
  54. 54. index.phpif ($redirectTo = checkSource()) { header("Location: $redirectTo"); die;}ControllerFront::getInstance()->dispatch();
  55. 55. • ControllerFront::importConf• router config URL
  56. 56. dispatch• URL•• Request• ControllerAction::runAction
  57. 57. runAction• Action• Plugin•
  58. 58. • classes/*
  59. 59. • Core.php• Obj.php• DBObj.php• DB.php
  60. 60. • Cookie.php• Session.php• Cache.php
  61. 61. • Debug.php• Log.php• Loader.php
  62. 62. • Request.php• Response.php
  63. 63. • ControllerFront.php• ControllerAction.php• ControllerActionPlugin.php• ControllerBusiness.php
  64. 64. • prepend.php(php -i |grep prepend) /opt/www.config/prepend.php• prepend.php ~/mt/config/prepend.php• config/*
  65. 65. prepend.php• ROOT/TS/DOMAIN_HOST• include_path•• Debug• autoload
  66. 66. autoload• Loader::registerAutoload Loader::load• class/Model/Controller/Helper
  67. 67. • http://bj.meituan.com/deal/959830.html• http://bj.meituan.com/deals/page2
  68. 68. • Macbook apache+php +mysql• mini web framework php/python/ ruby router dispatcher orm•

×