{"id":51347,"date":"2024-10-08T17:51:35","date_gmt":"2024-10-08T09:51:35","guid":{"rendered":"https:\/\/server.hk\/cnblog\/51347\/"},"modified":"2024-11-14T10:43:39","modified_gmt":"2024-11-14T02:43:39","slug":"ubuntu-15-10-%e4%b8%8b-lnmp-%e7%92%b0%e5%a2%83%e6%90%ad%e5%bb%ba%e5%92%8c-nginx-%e5%a4%9a%e7%ab%99%e9%bb%9e%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/51347\/","title":{"rendered":"Ubuntu 15.10 \u4e0b LNMP \u74b0\u5883\u642d\u5efa\u548c Nginx \u591a\u7ad9\u9ede\u914d\u7f6e"},"content":{"rendered":"<h1 id=\"ubuntu-15-10-%e4%b8%8b-lnmp-%e7%92%b0%e5%a2%83%e6%90%ad%e5%bb%ba%e5%92%8c-nginx-%e5%a4%9a%e7%ab%99%e9%bb%9e%e9%85%8d%e7%bd%ae-CCgYaoJnRr\">Ubuntu 15.10 \u4e0b LNMP \u74b0\u5883\u642d\u5efa\u548c Nginx \u591a\u7ad9\u9ede\u914d\u7f6e<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0cLNMP\uff08Linux, Nginx, MySQL, PHP\uff09\u67b6\u69cb\u56e0\u5176\u9ad8\u6548\u80fd\u548c\u9748\u6d3b\u6027\u800c\u53d7\u5230\u5ee3\u6cdb\u4f7f\u7528\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 Ubuntu 15.10 \u4e0a\u642d\u5efa LNMP \u74b0\u5883\uff0c\u4e26\u914d\u7f6e Nginx \u4ee5\u652f\u6301\u591a\u500b\u7db2\u7ad9\u3002<\/p>\n<h2 id=\"%e4%b8%80%e3%80%81%e5%ae%89%e8%a3%9d-lnmp-%e7%92%b0%e5%a2%83-CCgYaoJnRr\">\u4e00\u3001\u5b89\u88dd LNMP \u74b0\u5883<\/h2>\n<h3 id=\"1-%e6%9b%b4%e6%96%b0%e7%b3%bb%e7%b5%b1-CCgYaoJnRr\">1. \u66f4\u65b0\u7cfb\u7d71<\/h3>\n<pre><code>sudo apt-get update\nsudo apt-get upgrade<\/code><\/pre>\n<h3 id=\"2-%e5%ae%89%e8%a3%9d-nginx-CCgYaoJnRr\">2. \u5b89\u88dd Nginx<\/h3>\n<p>\u9996\u5148\uff0c\u6211\u5011\u9700\u8981\u5b89\u88dd Nginx\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u5b89\u88dd\uff1a<\/p>\n<pre><code>sudo apt-get install nginx<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5 Nginx\uff1a<\/p>\n<pre><code>sudo systemctl start nginx<\/code><\/pre>\n<p>\u4e26\u8a2d\u7f6e\u958b\u6a5f\u81ea\u555f\uff1a<\/p>\n<pre><code>sudo systemctl enable nginx<\/code><\/pre>\n<h3 id=\"3-%e5%ae%89%e8%a3%9d-mysql-CCgYaoJnRr\">3. \u5b89\u88dd MySQL<\/h3>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u5b89\u88dd MySQL \u6578\u64da\u5eab\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u5b89\u88dd\uff1a<\/p>\n<pre><code>sudo apt-get install mysql-server<\/code><\/pre>\n<p>\u5b89\u88dd\u904e\u7a0b\u4e2d\uff0c\u7cfb\u7d71\u6703\u63d0\u793a\u60a8\u8a2d\u7f6e MySQL \u7684 root \u5bc6\u78bc\uff0c\u8acb\u59a5\u5584\u8a18\u9304\u3002<\/p>\n<h3 id=\"4-%e5%ae%89%e8%a3%9d-php-CCgYaoJnRr\">4. \u5b89\u88dd PHP<\/h3>\n<p>\u6700\u5f8c\uff0c\u6211\u5011\u9700\u8981\u5b89\u88dd PHP \u53ca\u5176\u76f8\u95dc\u64f4\u5c55\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u5b89\u88dd\uff1a<\/p>\n<pre><code>sudo apt-get install php-fpm php-mysql<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u901a\u904e\u7de8\u8f2f PHP \u914d\u7f6e\u6587\u4ef6\u4f86\u8abf\u6574\u8a2d\u7f6e\uff1a<\/p>\n<pre><code>sudo nano \/etc\/php\/7.0\/fpm\/php.ini<\/code><\/pre>\n<p>\u5728\u6587\u4ef6\u4e2d\u627e\u5230 `cgi.fix_pathinfo`\uff0c\u5c07\u5176\u8a2d\u7f6e\u70ba 0\uff1a<\/p>\n<pre><code>cgi.fix_pathinfo=0<\/code><\/pre>\n<p>\u4fdd\u5b58\u4e26\u9000\u51fa\u7de8\u8f2f\u5668\uff0c\u7136\u5f8c\u91cd\u555f PHP-FPM \u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl restart php7.0-fpm<\/code><\/pre>\n<h2 id=\"%e4%ba%8c%e3%80%81%e9%85%8d%e7%bd%ae-nginx-%e6%94%af%e6%8c%81%e5%a4%9a%e7%ab%99%e9%bb%9e-CCgYaoJnRr\">\u4e8c\u3001\u914d\u7f6e Nginx \u652f\u6301\u591a\u7ad9\u9ede<\/h2>\n<h3 id=\"1-%e5%89%b5%e5%bb%ba%e7%b6%b2%e7%ab%99%e7%9b%ae%e9%8c%84-CCgYaoJnRr\">1. \u5275\u5efa\u7db2\u7ad9\u76ee\u9304<\/h3>\n<p>\u70ba\u6bcf\u500b\u7db2\u7ad9\u5275\u5efa\u4e00\u500b\u76ee\u9304\u3002\u4f8b\u5982\uff0c\u5047\u8a2d\u6211\u5011\u8981\u8a2d\u7f6e\u5169\u500b\u7db2\u7ad9\uff0c\u5206\u5225\u70ba example1.com \u548c example2.com\uff1a<\/p>\n<pre><code>sudo mkdir -p \/var\/www\/example1.com\/html\nsudo mkdir -p \/var\/www\/example2.com\/html<\/code><\/pre>\n<h3 id=\"2-%e8%a8%ad%e7%bd%ae%e6%ac%8a%e9%99%90-CCgYaoJnRr\">2. \u8a2d\u7f6e\u6b0a\u9650<\/h3>\n<p>\u8a2d\u7f6e\u76ee\u9304\u7684\u6b0a\u9650\uff0c\u4ee5\u4fbf Nginx \u53ef\u4ee5\u8a2a\u554f\uff1a<\/p>\n<pre><code>sudo chown -R www-data:www-data \/var\/www\/example1.com\/html\nsudo chown -R www-data:www-data \/var\/www\/example2.com\/html<\/code><\/pre>\n<h3 id=\"3-%e5%89%b5%e5%bb%ba-nginx-%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6-CCgYaoJnRr\">3. \u5275\u5efa Nginx \u914d\u7f6e\u6587\u4ef6<\/h3>\n<p>\u70ba\u6bcf\u500b\u7db2\u7ad9\u5275\u5efa\u4e00\u500b Nginx \u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code>sudo nano \/etc\/nginx\/sites-available\/example1.com<\/code><\/pre>\n<p>\u5728\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u5167\u5bb9\uff1a<\/p>\n<pre><code>server {\n    listen 80;\n    server_name example1.com www.example1.com;\n\n    root \/var\/www\/example1.com\/html;\n    index index.php index.html index.htm;\n\n    location \/ {\n        try_files $uri $uri\/ =404;\n    }\n\n    location ~ .php$ {\n        include snippets\/fastcgi-php.conf;\n        fastcgi_pass unix:\/var\/run\/php\/php7.0-fpm.sock;\n        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n        include fastcgi_params;\n    }\n}<\/code><\/pre>\n<p>\u5c0d\u65bc\u7b2c\u4e8c\u500b\u7db2\u7ad9\uff0c\u91cd\u8907\u4e0a\u8ff0\u6b65\u9a5f\uff0c\u5275\u5efa\u914d\u7f6e\u6587\u4ef6\u4e26\u4fee\u6539\u76f8\u61c9\u7684\u57df\u540d\u548c\u76ee\u9304\u3002<\/p>\n<h3 id=\"4-%e5%95%9f%e7%94%a8%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6-CCgYaoJnRr\">4. \u555f\u7528\u914d\u7f6e\u6587\u4ef6<\/h3>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u555f\u7528\u9019\u4e9b\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code>sudo ln -s \/etc\/nginx\/sites-available\/example1.com \/etc\/nginx\/sites-enabled\/\nsudo ln -s \/etc\/nginx\/sites-available\/example2.com \/etc\/nginx\/sites-enabled\/<\/code><\/pre>\n<h3 id=\"5-%e6%b8%ac%e8%a9%a6-nginx-%e9%85%8d%e7%bd%ae-CCgYaoJnRr\">5. \u6e2c\u8a66 Nginx \u914d\u7f6e<\/h3>\n<p>\u5728\u91cd\u65b0\u555f\u52d5 Nginx \u4e4b\u524d\uff0c\u8acb\u6e2c\u8a66\u914d\u7f6e\u662f\u5426\u6b63\u78ba\uff1a<\/p>\n<pre><code>sudo nginx -t<\/code><\/pre>\n<p>\u5982\u679c\u6c92\u6709\u932f\u8aa4\uff0c\u5247\u53ef\u4ee5\u91cd\u555f Nginx\uff1a<\/p>\n<pre><code>sudo systemctl restart nginx<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-CCgYaoJnRr\">\u7e3d\u7d50<\/h2>\n<p>\u901a\u904e\u4ee5\u4e0a\u6b65\u9a5f\uff0c\u60a8\u5df2\u6210\u529f\u5728 Ubuntu 15.10 \u4e0a\u642d\u5efa\u4e86 LNMP \u74b0\u5883\u4e26\u914d\u7f6e\u4e86 Nginx \u4ee5\u652f\u6301\u591a\u500b\u7db2\u7ad9\u3002\u9019\u7a2e\u67b6\u69cb\u4e0d\u50c5\u9ad8\u6548\uff0c\u9084\u80fd\u9748\u6d3b\u61c9\u5c0d\u4e0d\u540c\u7684\u9700\u6c42\u3002\u5982\u679c\u60a8\u9700\u8981\u66f4\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8003\u616e\u4f7f\u7528\u6211\u5011\u7684\u670d\u52d9\uff0c\u8b93\u60a8\u7684\u7db2\u7ad9\u904b\u884c\u5f97\u66f4\u52a0\u9806\u66a2\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to set up an LNMP environment on Ubuntu 15.10 and configure Nginx for multiple sites efficiently. Step-by-step guide included.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-51347","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/51347","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=51347"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/51347\/revisions"}],"predecessor-version":[{"id":51348,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/51347\/revisions\/51348"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=51347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=51347"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=51347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}