尊龙凯时人生就是博

ÔõÑùʹÓÃNginxʵÏÖ»ùÓÚÓòÃûºÍ·¾¶µÄÐéÄâÖ÷»úÉèÖÃ

ÔõÑùʹÓÃnginxʵÏÖ»ùÓÚÓòÃûºÍ·¾¶µÄÐéÄâÖ÷»úÉèÖÃ

СÐò£º

ÔÚÍøÂçÓ¦Óÿª·¢ÖÐ £¬¾­³£ÐèÒªÉèÖöà¸öÐéÄâÖ÷»úÀ´Ìṩ²î±ðµÄЧÀÍ¡£NginxÊÇÒ»¸ö¸ßÐÔÄܵÄHTTPºÍ·´ÏòÊðÀíЧÀÍÆ÷ £¬Í¨¹ýʹÓÃNginx £¬ÎÒÃÇ¿ÉÒÔºÜÀû±ãµØʵÏÖ»ùÓÚÓòÃûºÍ·¾¶µÄÐéÄâÖ÷»úÉèÖᣱ¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃNginxÀ´ÊµÏÖÕâÑùµÄÉèÖà £¬²¢¸ø³öÏìÓ¦µÄ´úÂëʾÀý¡£

Ò»¡¢»ùÓÚÓòÃûµÄÐéÄâÖ÷»úÉèÖÃ

ÔÚNginxµÄÉèÖÃÎļþÖÐ £¬Ê¹ÓÃserver¿éÀ´ÉèÖÃÐéÄâÖ÷»ú¡£ÔÚ»ùÓÚÓòÃûµÄÐéÄâÖ÷»úÉèÖÃÖÐ £¬ÎÒÃÇ¿ÉÒÔͨ¹ýserver_nameÖ¸ÁîÀ´Ö¸¶¨ÓòÃû £¬²¢ÉèÖÃÏìÓ¦µÄЧÀÍ¡£

ʾÀý´úÂ룺

server {

listen 80;
server_name example.com;
root /var/www/example;
index index.html;

location / {
    try_files $uri $uri/ =404;
}

µÇ¼ºó¸´ÖÆ

}

ÔÚÉÏÊöʾÀý´úÂëÖÐ £¬ÉèÖÃÁËÒ»¸öÃûΪexample.comµÄÐéÄâÖ÷»ú¡£ÆäÖÐ £¬listenÖ¸ÁîÓÃÓÚÖ¸¶¨Nginx¼àÌýµÄ¶Ë¿ÚºÅ £¬server_nameÖ¸ÁîÓÃÓÚÖ¸¶¨ÓòÃû¡£rootÖ¸ÁîÓÃÓÚÖ¸¶¨ÍøÕ¾µÄ¸ùĿ¼ £¬indexÖ¸ÁîÓÃÓÚÉèÖÃĬÈϵÄÊ×Ò³Îļþ¡£

¶þ¡¢»ùÓÚ·¾¶µÄÐéÄâÖ÷»úÉèÖÃ

³ýÁË»ùÓÚÓòÃûµÄÐéÄâÖ÷»úÉèÖà £¬Nginx»¹Ö§³Ö»ùÓÚ·¾¶µÄÐéÄâÖ÷»úÉèÖá£Í¨¹ýÉèÖÃlocation¿é £¬ÎÒÃÇ¿ÉÒÔƾ֤»á¼ûµÄ·¾¶À´Ìṩ²î±ðµÄЧÀÍ¡£

ʾÀý´úÂ룺

server {

listen 80;
server_name example.com;

location / {
    root /var/www/example1;
    index index.html;
}

location /blog {
    root /var/www/example2;
    index index.php;
}

µÇ¼ºó¸´ÖÆ

}

ÔÚÉÏÊöʾÀý´úÂëÖÐ £¬ÉèÖÃÁËÒ»¸öÃûΪexample.comµÄÐéÄâÖ÷»ú £¬°üÀ¨Á½¸ölocation¿é¡£µÚÒ»¸ölocation¿éÉèÖÃÁ˸ù·¾¶/µÄЧÀÍ £¬rootÖ¸ÁîÉèÖÃΪ/var/www/example1 £¬indexÖ¸ÁîÉèÖÃΪindex.html¡£µÚ¶þ¸ölocation¿éÉèÖÃÁË·¾¶Îª/blogµÄЧÀÍ £¬rootÖ¸ÁîÉèÖÃΪ/var/www/example2 £¬indexÖ¸ÁîÉèÖÃΪindex.php¡£

Èý¡¢Í¬Ê±Ê¹ÓÃÓòÃûºÍ·¾¶µÄÐéÄâÖ÷»úÉèÖÃ

ÔÚÏÖʵӦÓÃÖÐ £¬ÎÒÃÇͨ³£ÐèҪͬʱʹÓÃÓòÃûºÍ·¾¶À´ÉèÖöà¸öÐéÄâÖ÷»ú¡ £¿ÉÒÔͨ¹ý×éºÏʹÓÃserver_nameºÍlocationÖ¸ÁîÀ´ÊµÏÖÕâÑùµÄÉèÖá£

ʾÀý´úÂ룺

server {

listen 80;
server_name example.com;

location / {
    root /var/www/example1;
    index index.html;
}

µÇ¼ºó¸´ÖÆ

}

server {

listen 80;
server_name blog.example.com;

location / {
    root /var/www/example2;
    index index.php;
}

µÇ¼ºó¸´ÖÆ

}

ÔÚÉÏÊöʾÀý´úÂëÖÐ £¬ÉèÖÃÁËÁ½¸öÐéÄâÖ÷»ú¡£µÚÒ»¸öÐéÄâÖ÷»úʹÓÃexample.comÓòÃû £¬²¢ÌṩÒÔ/Ϊ·¾¶µÄЧÀÍ £»µÚ¶þ¸öÐéÄâÖ÷»úʹÓÃblog.example.comÓòÃû £¬²¢ÌṩÒÔ/Ϊ·¾¶µÄЧÀÍ¡£Á½¸öÐéÄâÖ÷»ú»®·ÖÖ¸¶¨Á˲î±ðµÄ¸ùĿ¼ºÍÊ×Ò³Îļþ¡£

½áÂÛ£º

ͨ¹ýNginxµÄÐéÄâÖ÷»úÉèÖà £¬ÎÒÃÇ¿ÉÒÔÀû±ãµØΪ²î±ðµÄÓòÃûºÍ·¾¶Ìṩ²î±ðµÄЧÀÍ¡£ÔÚÏÖʵӦÓÃÖÐ £¬¿ÉÒÔÎÞаµØ×éºÏʹÓÃÓòÃûºÍ·¾¶À´ÉèÖöà¸öÐéÄâÖ÷»ú¡£Ï£Íû±¾ÎÄÄÜ×ÊÖú¶ÁÕ߸üºÃµØÃ÷È·ÔõÑùʹÓÃnginxʵÏÖ»ùÓÚÓòÃûºÍ·¾¶µÄÐéÄâÖ÷»úÉèÖá£

²Î¿¼´úÂ룺

https://www.nginx.com/resources/wiki/start/topics/examples/full/

https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04

ÒÔÉϾÍÊÇÔõÑùʹÓÃNginxʵÏÖ»ùÓÚÓòÃûºÍ·¾¶µÄÐéÄâÖ÷»úÉèÖõÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是博ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是博ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

13452372176

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ