LNMPベースのE-コマースWebサイトの導入を実現

11160 ワード

一、LNMPアーキテクチャ設計
サーバA:centos 7.3 nginxサービスサーバB:centos 7を配備する.3 php-fpmサービスサーバC:centos 7を配備する.3 mariadbサービスの導入
二、nginxサービスのインストールと構成
1.インストール
 yum install nginx 

2.構成
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf
#vim /etc/nginx/nginx.conf
user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
error_log  /var/log/nginx/error.log  info;

#pid        /var/log/nginx/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;

    server {
        listen       80;
        server_name  localhost;
        index  index.php index.html index.htm;

        #charset koi8-r;

        access_log  /var/log/nginx/host.access.log  main;

        location / {
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
        #    root           html;
        #  php   IP 9000  
            fastcgi_pass   172.17.17.173:9000;
            fastcgi_index  index.php;
#  php    
            fastcgi_param  SCRIPT_FILENAME  /data/web/xiaomi$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}
nginx -t
        

3.サービスの開始
#  
              ,          
              ,            
             
systemctl start nginx

三、PHPサービス
1.インストール
yum install php-fpm php-mysql -y

2.構成
php.ini
vim /etc/php.ini
#      
    short_open_tag = on
    date.timezone = Asia/Shanghai

/etc/php-fpm.d/www.conf
vim  /etc/php-fpm.d/www.conf
#    4 
#    9000      9000  
listen = 9000
listen.allowed_clients = 172.17.16.173
user = nobody
group = nobody
#php     apache    

3.サービス開始
systemctl  start  php-fpm

四、mariadbサービス
1.インストール、サービス開始、セキュリティ強化スクリプトの実行
 yum  -y  install mariadb-server
 systemctl start mariadb
 mysql_secure_installation 

2.データベースの作成、ユーザー、権限の付与
create database xiaomi;
grant all on xiaomi.* to xiaomiuser@'%' identified by 'xiaomipassword';

五、ウェブサイトのソースコードの配置
1.ウェブサイトのソースコードをphpサーバーの/data/web/xiaomiディレクトリの下に置く
mkdir -p /data/web/xiaomi
unzip -d /data/web/xiaomi/  xiaomi.zip

2.サイトのソースコードの各種ファイル権限を修正する
# nginx        user  nobody;
# php php.ini     ,   user  nobody;group nobody;
chown   -R  nobody.nobody  /data/web/xiaomi

3.接続データベースの設定の変更
ウェブサイトのソースコードの中でconfig.phpは接続データベースの設定を記録しています
#      
//       3306       ,          
$db_host   = "172.17.17.174:3306";

//      
$db_name   = "xiaomi";

//       
$db_user   = "xiaomiuser";

//      
$db_pass   = "xiaomipassword";

4.入るhttp://172.17.16.173/ebak/index.php
  ---->    ---->    

六、完成