美文网首页
lamp与lnmp

lamp与lnmp

作者: 子非鱼_aee3 | 来源:发表于2019-10-24 13:52 被阅读0次

    centos7环境

    1.lamp:

    yum -y install httpd httpd-devel

    yum -y install mariadb mariadb-server

    yum -y install php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash

    启动apache,mariadb并设置开机自启(systemctl start|stop|restart|enable|disable)

    mysqladmin -u root password 123456  #设置mariadb管理员密码

    mysql -u root -p  #进入数据库

    showdatabases;  #查看

    将网站源码scp到/var/www/html目录下

    2.lnmp:

    默认centos源中没有nginx包,epel源

    yum list | grep epel

    yum -y install epel-release //安装epel源

    yum makecache  //把服务器的包信息下载到本地电脑缓存起来

    yum -y install nginx

    yum -y install mariadb mariadb-server

    yum -y install php-fpm php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash

    启动nginx,mariadb,php-fpm并设置开机自启(systemctl start|stop|restart|enable|disable)

    mysqladmin -u root password 123456  #设置mariadb管理员密码

    mysql -u root -p  #进入数据库

    showdatabases;  #查看

    修改php-fpm配置文件vi /etc/php-fpm.d/www.conf

    修改nginx配置文件vi /etc/nginx/nginx.conf

    若nginx做为web服务器,如下:

    user nginx;

    worker_processes auto;

    error_log /var/log/nginx/error.log;

    pid /run/nginx.pid;

    include /usr/share/nginx/modules/*.conf;

    events {

        worker_connections 1024;

    }

    http {

        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;

        tcp_nodelay        on;

        keepalive_timeout  65;

        types_hash_max_size 2048;

        include            /etc/nginx/mime.types;

        default_type        application/octet-stream;

        include /etc/nginx/conf.d/*.conf;

        include /etc/nginx/default.d/*.conf;

        server {

            listen      80 default_server;

            listen      [::]:80 default_server;

            server_name  _;

            root        /usr/share/nginx/html;

            index        index.php;

            location ~ \.php$ {

                   root /usr/share/nginx/html;  #指定php的根目录

                   fastcgi_pass 127.0.0.1:9000;  #php-fpm的默认端口是9000

                   fastcgi_index index.html index.php;  #默认主页

                   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

                   include fastcgi_params;

            }

            location / {

            }

            error_page 404 /404.html;

                location = /40x.html {

            }

            error_page 500 502 503 504 /50x.html;

                location = /50x.html {

            }

        }

    }

    在/usr/share/nginx/html中建立测试文件

    vi info.php内容为:<?php phpinfo(); ?>

    随后访问访问此页面,看解析是否正常

    若nginx做为反向代理,如下:

    user nginx;

    worker_processes auto;

    error_log /var/log/nginx/error.log;

    pid /run/nginx.pid;

    include /usr/share/nginx/modules/*.conf;

    events {

        worker_connections 1024;

    }

    http {

        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;

        tcp_nodelay        on;

        keepalive_timeout  65;

        types_hash_max_size 2048;

        include            /etc/nginx/mime.types;

        default_type        application/octet-stream;

        include /etc/nginx/conf.d/*.conf;

        include /etc/nginx/default.d/*.conf;

        upstream web1 {

            server 192.168.0.137  weight=1; #weight表示权重,越高被分配的几率越大

          #server 192.168.0.17  weight=1;

          #ip_hash;

        }

        server{

            listen 80;

            server_name www.abc.org;

            access_log  /var/log/nginx/abc.log;

            location / {

                root /home/web1_root;

                proxy_pass http://web1;  

                proxy_read_timeout 300;

                proxy_connect_timeout 300;

                proxy_redirect    off;

                proxy_set_header  X-Forwarded-Proto $scheme;

                proxy_set_header  Host              $http_host;

                proxy_set_header  X-Real-IP        $remote_addr;

            }

        }

    }

    相关文章

      网友评论

          本文标题:lamp与lnmp

          本文链接:https://www.haomeiwen.com/subject/jlgrvctx.html