LNMP部署和双站点

一、LNMP部署
1、拉去镜像

docker pull 2233466866/lnmp


2、运行镜像为容器

docker run -d -it -p 8090:80 -p 8080:8080 -v /root/www/:/root/www/ --name hs0703_np --privileged 017

-d 后台运行
-it 可以进行交互
-p 端口映射  服务器端口:容器端口
-v 数据卷映射  服务器目录:容器内目录
--name 容器名字
--privileged  给root权限
017 镜像ID

 3、进入容器

docker exec -it 容器ID bash

 4、容器内目录和命令介绍

 /usr/local/nginx/conf/                  nginx配置文件
/www                                           放置项目文件
systemctl reload nginx                重新加载nginx配置文件
ss -nalt                                        查看对外的端口
ps -aux | grep  nginx/php            查看服务是否在跑

二、双站点

 1、找到/usr/local/nginx/conf/nginx.conf 文件

user                    www;
worker_processes        auto;
worker_cpu_affinity     auto;
pid                     logs/nginx.pid;

events {
    worker_connections  102400;
}

http {
    charset             utf-8;
    server_tokens       off;

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

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

    client_max_body_size 20M;

    sendfile            on;
    keepalive_timeout   20;

    gzip                on;
    gzip_vary           on;
    gzip_comp_level     1;
    gzip_types          text/css application/javascript application/json image/png image/webp image/apng image/jpeg image/x-icon;

    error_log           /www/z_error.log;
    access_log          /www/z_$host.log main;
    server {
        listen      80;
        server_name www.test.com;
        root         /www/;

        location / {
            index   index.php index.html index.htm;
        }

        location ~* \.php {
            include                 fastcgi_params;
            fastcgi_index           index.php;
            fastcgi_pass            127.0.0.1:9000;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_param           PATH_INFO       $fastcgi_path_info;
            fastcgi_param           SCRIPT_NAME     $fastcgi_script_name;
            fastcgi_param           SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
    }
    server {
        listen      80;
        server_name www.test.com;
        root         /www/;

        location / {
            index   index.php index.html index.htm;
        }

        location ~* \.php {
            include                 fastcgi_params;
            fastcgi_index           index.php;
            fastcgi_pass            127.0.0.1:9000;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_param           PATH_INFO       $fastcgi_path_info;
            fastcgi_param           SCRIPT_NAME     $fastcgi_script_name;
            fastcgi_param           SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
    }

}

2、主要就是server里边的内容,要几个站点就建几个server

3、server要修改listen(端口)、server_name(域名)、root(项目目录)---上面代码我没有修改这三项,根据自己需求更改。

4、重新加载nginx配置

systemctl reload nginx
  • 9
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Ansible角色是Ansible中的一种组织方式,它是一组任务、变量、文件和模板的集合,用于实现某个特定功能。在这个问题中,我们可以使用Ansible角色来部署LNMPLinux、Nginx、MySQL和PHP)堆栈。 以下是一个简单的LNMP Ansible角色部署示例: 1. 创建一个名为“lnmp”的Ansible角色目录: ``` mkdir roles/lnmp ``` 2. 在lnmp目录中创建一个tasks目录: ``` mkdir roles/lnmp/tasks ``` 3. 在tasks目录中创建一个main.yml文件,其中包含以下任务: ``` - name: Install Nginx yum: name: nginx state: present - name: Start Nginx service service: name: nginx state: started - name: Install MySQL yum: name: mysql-server state: present - name: Start MySQL service service: name: mysqld state: started - name: Install PHP yum: name: php state: present - name: Install PHP-FPM yum: name: php-fpm state: present - name: Start PHP-FPM service service: name: php-fpm state: started ``` 这些任务将安装和启动Nginx、MySQL和PHP-FPM服务。 4. 在lnmp目录中创建一个vars目录: ``` mkdir roles/lnmp/vars ``` 5. 在vars目录中创建一个main.yml文件,其中包含以下变量: ``` --- nginx_conf_file: /etc/nginx/nginx.conf mysql_root_password: mysecretpassword php_conf_dir: /etc/php.d/ ``` 这些变量将用于配置Nginx、MySQL和PHP的设置。 6. 在lnmp目录中创建一个templates目录: ``` mkdir roles/lnmp/templates ``` 7. 在templates目录中创建一个nginx.conf.j2模板文件: ``` worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; server { listen 80; server_name localhost; location / { root /var/www/html; index index.php index.html index.htm; } location ~ \.php$ { root /var/www/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } } ``` 这个模板将用于生成Nginx的配置文件。 8. 在tasks目录中创建一个configure.yml文件,其中包括以下任务: ``` - name: Copy Nginx configuration file template: src: nginx.conf.j2 dest: "{{ nginx_conf_file }}" mode: '0644' - name: Set MySQL root password mysql_user: name: root password: "{{ mysql_root_password }}" login_unix_socket: /var/lib/mysql/mysql.sock - name: Copy PHP configuration file copy: src: php.ini dest: "{{ php_conf_dir }}" mode: '0644' ``` 这些任务将生成Nginx配置文件、设置MySQL root密码和复制PHP配置文件。 9. 在lnmp目录中创建一个files目录: ``` mkdir roles/lnmp/files ``` 10. 在files目录中创建php.ini文件: ``` memory_limit = 128M upload_max_filesize = 64M post_max_size = 64M ``` 这个文件将被复制到PHP配置目录中。 11. 在lnmp目录中创建一个meta目录: ``` mkdir roles/lnmp/meta ``` 12. 在meta目录中创建一个main.yml文件,其中包含以下元数据: ``` --- dependencies: - { role: geerlingguy.repo-epel } - { role: geerlingguy.mysql } ``` 这些元数据将指定依赖项,以便安装EPEL存储库和MySQL角色。 13. 在playbook中使用lnmp角色: ``` - hosts: webserver become: true roles: - lnmp ``` 这个playbook将在webserver主机上使用lnmp角色。 这就是一个简单的LNMP Ansible角色部署示例。当然,还有很多其他的配置选项和任务可以添加到这个角色中,以满足不同的需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值