{"id":617,"date":"2021-10-25T15:45:00","date_gmt":"2021-10-25T15:45:00","guid":{"rendered":"https:\/\/262235.xyz\/?p=617"},"modified":"2021-10-25T15:45:00","modified_gmt":"2021-10-25T15:45:00","slug":"617","status":"publish","type":"post","link":"https:\/\/lyvba.com\/index.php\/2021\/10\/25\/617\/","title":{"rendered":"LNMP\u586b\u5751\u7b14\u8bb0: docker-compose.yml  \u90e8\u7f72 Mysql 5.7 \u548c php:5.5.38-fpm \u548c\u6700\u65b0 Nginx"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/10\/2804828533.webp\" alt=\"lnmp.png_new.webp\" title=\"lnmp.png_new.webp\"><\/p>\n<h3>\u90e8\u7f72\u9700\u8981\u7684\u6587\u4ef6\u6253\u5305  <a href=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/10\/408646653.tar\">lnmp.tar<\/a><\/h3>\n<p>\u6628\u5929\u6709\u670b\u53cb\u8981\u4f7f\u7528php5.3\u624d\u80fd\u8fd0\u884c\u4e00\u4e2a\u6846\u67b6\u7a0b\u5e8f\uff0cDockerHub\u627e\u5230\u53ea\u6709 <code>php:5.5.38-fpm<\/code> \u955c\u50cf\uff0c\u7136\u540e\u5c31\u662f\u4f7f\u7528 docker-compose.yml  \u90e8\u7f72 LNMP\uff0c\u56e0\u4e3aNginx\u548cPhp-Fpm\u4e0d\u662f\u540c\u4e00\u4e2a\u5bb9\u5668\uff0c\u641e\u4e86\u4e2a\u628a\u5c0f\u65f6 phpinfo \u624d\u8dd1\u8d77\u6765\uff0c\u4f46\u662f\u81ea\u5df1\u4e5f\u6ca1\u6709\u6478\u900f\u3002<br \/>\u6211\u662f\u4f7f\u7528 php-fpm \u5bb9\u5668\u4e2d apt\u5b89\u88c5\u4e00\u4e2a \u4f4e\u7248\u672cNginx\uff0c\u81ea\u52a8\u914d\u7f6e\u8d77\u6765\uff0c\u4f46\u662f\u5176\u5b9e\u6709\u5f88\u591a\u5751\uff0c\u540e\u6765\u5728\u53e6\u4e00\u4e2a\u865a\u62df\u673a\u73af\u5883\u641e\u5230\u665a\u4e0a11\u70b9\u624d\u7b97\u6b63\u5f0f\u6478\u900f\u4e86\u3002<\/p>\n<h2><code>docker-compose.yml<\/code><\/h2>\n<pre><code>version: '3.1'\nservices:\n    db:\n        image: mysql:5.7\n        container_name: mysql\n        command: --default-authentication-plugin=mysql_native_password\n        restart: always\n        volumes:\n            - \/data\/mysql:\/var\/lib\/mysql\n        environment:\n            MYSQL_DATABASE: test\n            MYSQL_ROOT_PASSWORD: Mysql@2021\n\n    adminer:\n        image: adminer\n        container_name: adminer\n        restart: always\n        ports:\n            - 10086:8080\n\n    nginx:\n        image: nginx\n        container_name: nginx\n        restart: always\n        volumes:\n            - \/data\/www\/:\/var\/www\/html\n        ports:\n            - 80:80\n            - 443:443\n\n    php:\n        image: php:5.5.38-fpm\n        container_name: php\n        restart: always\n        volumes:\n            - \/data\/www\/:\/var\/www\/html\n        ports:\n            - 9000:9000\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/10\/315679107.png\" alt=\"php.png\" title=\"php.png\"><\/p>\n<h2>\u91cd\u70b9\u6765\u8bf4 docker-compose.yml,\u4f7f\u7528\u8fd9\u4e2a\u65b9\u5f0f\u90e8\u7f72\u7684\u5bb9\u5668\u90fd\u53ef\u4ee5\u4f7f\u7528\u5bb9\u5668\u540d\u548c\u7ec4\u4ef6\u540d\u6765\u4ee3\u66ffIP\u4e92\u76f8\u8bbf\u95ee\u3002<\/h2>\n<h2>\u6bd4\u5982\u4f7f\u7528\u8bbf\u95ee\u6570\u636e\u5e93\u4f7f\u7528 db\u6216\u8005mysql\u8fde\u63a5\uff0c php:9000 \u7528\u6765\u8fde\u63a5php-fpm , \u6d4b\u8bd5http\u4f7f\u7528 curl nginx:80<\/h2>\n<h2>php-fpm\u5bb9\u5668\u7684\u76ee\u5f55\u6302\u8f7d\u662f\u91cd\u70b9\uff0c\u6628\u5929\u4e00\u76f4\u88ab\u5751\u5728\u8fd9\u91cc\uff0c\u663e\u793a\u9519\u8bef <code>File not found.<\/code> \u800c\u7f51\u4e0a\u7684\u6587\u7ae0\u90fd\u6ca1\u6709\u63d0\u8fd9\u4e2a\u91cd\u70b9\u3002<\/h2>\n<h2>\u90e8\u7f72\u548c\u4fee\u6539\u914d\u7f6e\u547d\u4ee4<\/h2>\n<pre><code># \u5b89\u88c5 docker-compose \u90e8\u7f72\u5de5\u5177\nwget https:\/\/lyvba.com\/docker-compose  -O \/usr\/local\/bin\/docker-compose\nchmod +x \/usr\/local\/bin\/docker-compose\n# \u5148\u5efa\u7acb docker-compose.yml \uff0c\u7136\u540e\u4f7f\u7528\u547d\u4ee4\u90e8\u7f72\ndocker-compose up -d\ndocker ps -a\ndocker cp \/usr\/bin\/nano nginx:\/usr\/bin\ndocker exec -it nginx bash\nmkdir -p \/var\/www\/html\/   # \u5b98\u65b9nginx\u9ed8\u8ba4\u6ca1\u8fd9\u4e2a\u76ee\u5f55\uff0c\u6240\u4ee5\u8981\u5efa\u7acb\u4e00\u4e2a\nnano \/etc\/nginx\/conf.d\/default.conf\nnginx -t\nnginx -s reload\ndocker restart nginx<\/code><\/pre>\n<h3>\u5728\u5bbf\u4e3b\u673a <code>\/data\/www\/<\/code> \u76ee\u5f55\u4e2d\u521b\u5efa <code>index.php<\/code> \u6587\u4ef6\uff0c\u7528\u4ee5 Nginx Web \u670d\u52a1\u5668\u6d4b\u8bd5 PHP-FPM<\/h3>\n<pre><code>&lt;?php phpinfo(); ?&gt;<\/code><\/pre>\n<h2>Nginx \u914d\u7f6e\uff0c\u53c2\u8003apt\u5b89\u88c5\u7684nginx\u914d\u7f6e\uff0c\u800c\u4e0d\u662f\u5b98\u65b9\u955c\u50cf\u7684\u914d\u7f6e<\/h2>\n<ul>\n<li>\n<p>Nginx \u53cd\u5411\u4ee3\u7406 Php-fpm \u89e3\u91ca php\u811a\u672c\uff0c\u914d\u7f6e\u4e24\u884c\u547d\u4ee4<\/p>\n<pre><code>include snippets\/fastcgi-php.conf;  # fastcgi\u914d\u7f6e\uff0cfastcgi-php.conf \u6587\u4ef6\u53c8\u5305\u542b fastcgi.conf\nfastcgi_pass php:9000;  # php:9000 \u662f Php-fpm\u5bb9\u5668\u5f00\u653e\u7684\u7aef\u53e3<\/code><\/pre>\n<\/li>\n<li>\u6240\u4ee5\u5b9e\u9645\u90e8\u7f72\u7684\u65f6\u5019 \u5b8c\u5168\u53ef\u4ee5\u628a\u4e09\u4e2a\u6587\u4ef6\u5199\u5230\u4e00\u4e2a\u652f\u6301ssl\u8bc1\u4e66\u7684 https.conf \u914d\u7f6e\u6587\u4ef6\u4e2d<\/li>\n<\/ul>\n<h3><code>default.conf<\/code><\/h3>\n<pre><code>server {\n    listen 80 default_server;\n    listen [::]:80 default_server;\n\n    # SSL configuration\n    #\n    # listen 443 ssl default_server;\n    # listen [::]:443 ssl default_server;\n    #\n    # Self signed certs generated by the ssl-cert package\n    # Don't use them in a production server!\n    #\n    # include snippets\/snakeoil.conf;\n\n    root \/var\/www\/html;\n\n    # Add index.php to the list if you are using PHP\n    index index.html index.php index.htm index.nginx-debian.html;\n\n    server_name _;\n\n    location \/ {\n        # First attempt to serve request as file, then\n        # as directory, then fall back to displaying a 404.\n        try_files $uri $uri\/ =404;\n    }\n\n    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000\n    #\n    location ~ .php$ {\n        include snippets\/fastcgi-php.conf;\n    #\n    #    # With php5-cgi alone:\n        fastcgi_pass php:9000;\n    #    # With php5-fpm:\n    #    fastcgi_pass unix:\/var\/run\/php5-fpm.sock;\n    }\n\n    # deny access to .htaccess files, if Apache's document root\n    # concurs with nginx's one\n    #\n    #location ~ \/.ht {\n    #    deny all;\n    #}\n}\n<\/code><\/pre>\n<h3><code>fastcgi.conf<\/code><\/h3>\n<pre><code>fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;\nfastcgi_param  QUERY_STRING       $query_string;\nfastcgi_param  REQUEST_METHOD     $request_method;\nfastcgi_param  CONTENT_TYPE       $content_type;\nfastcgi_param  CONTENT_LENGTH     $content_length;\n\nfastcgi_param  SCRIPT_NAME        $fastcgi_script_name;\nfastcgi_param  REQUEST_URI        $request_uri;\nfastcgi_param  DOCUMENT_URI       $document_uri;\nfastcgi_param  DOCUMENT_ROOT      $document_root;\nfastcgi_param  SERVER_PROTOCOL    $server_protocol;\nfastcgi_param  HTTPS              $https if_not_empty;\n\nfastcgi_param  GATEWAY_INTERFACE  CGI\/1.1;\nfastcgi_param  SERVER_SOFTWARE    nginx\/$nginx_version;\n\nfastcgi_param  REMOTE_ADDR        $remote_addr;\nfastcgi_param  REMOTE_PORT        $remote_port;\nfastcgi_param  SERVER_ADDR        $server_addr;\nfastcgi_param  SERVER_PORT        $server_port;\nfastcgi_param  SERVER_NAME        $server_name;\n\n# PHP only, required if PHP was built with --enable-force-cgi-redirect\nfastcgi_param  REDIRECT_STATUS    200;<\/code><\/pre>\n<h3><code>snippetsfastcgi-php.conf<\/code><\/h3>\n<pre><code># regex to split $uri to $fastcgi_script_name and $fastcgi_path\nfastcgi_split_path_info ^(.+?.php)(\/.*)$;\n\n# Check that the PHP script exists before passing it\ntry_files $fastcgi_script_name =404;\n\n# Bypass the fact that try_files resets $fastcgi_path_info\n# see: http:\/\/trac.nginx.org\/nginx\/ticket\/321\nset $path_info $fastcgi_path_info;\nfastcgi_param PATH_INFO $path_info;\n\nfastcgi_index index.php;\ninclude fastcgi.conf;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u90e8\u7f72\u9700\u8981\u7684\u6587\u4ef6\u6253\u5305 lnmp.tar \u6628\u5929\u6709\u670b\u53cb\u8981\u4f7f\u7528php5.3\u624d\u80fd\u8fd0\u884c\u4e00\u4e2a\u6846\u67b6\u7a0b\u5e8f\uff0cDocker [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,8],"tags":[],"class_list":["post-617","post","type-post","status-publish","format-standard","hentry","category-docker","category-linux"],"_links":{"self":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/617","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/comments?post=617"}],"version-history":[{"count":0,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/617\/revisions"}],"wp:attachment":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media?parent=617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/categories?post=617"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/tags?post=617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}