如何同时使用 WSL Ubuntu 和 Docker?

遇到的问题:从你的 wsl –list –verbose 输出可以看出,你当前默认的 WSL 发行版是 docker-desktop,而不是标准的 Ubuntu/Debian。这是 Docker Desktop 在安装时自动创建的专用 WSL 发行版,主要用于运行 Docker 容器,并不适合直接作为 Linux 开发环境使用(缺少 apt/sudo 等基本工具)。给出了下面三种解决方案:

📌 关键区别

环境 适合场景 管理方式 软件安装方式
标准 WSL (Ubuntu) 日常 Linux 开发 wsl 命令 sudo apt install
Docker Desktop WSL 运行 Docker 引擎 Docker 自动管理 不推荐直接修改
Docker 容器 隔离的应用环境 docker 命令 容器内 apt

✅ 最终建议

选择方案 1(标准 WSL Ubuntu),这是最稳定、最接近原生 Linux 开发环境的方式。
只需在 PowerShell 中运行:

powershell
复制
wsl --install -d Ubuntu
wsl --set-default Ubuntu
wsl  # 进入 Ubuntu 安装软件
#sudo apt install -y nginx fcgiwrap python3
sudo -i
apt update && apt install -y nginx fcgiwrap python3

是的!选用方案 1(标准 WSL Ubuntu)后,Docker 仍然可以正常运行,而且这是官方推荐的最佳实践。以下是关键细节和配置方法:


🔧 如何同时使用 WSL Ubuntu 和 Docker?

1️⃣ Docker Desktop 的 WSL 集成(自动模式)

  • 安装 Docker Desktop 时,它会自动创建 docker-desktop WSL 发行版(你之前看到的),但你的 Ubuntu WSL 也可以直接访问 Docker
  • 确保开启 WSL 集成
    1. 打开 Docker Desktop → SettingsResourcesWSL Integration
    2. 勾选你的 Ubuntu 发行版(如 Ubuntu)并点击 Apply & Restart

2️⃣ 验证 Docker 是否在 Ubuntu 中可用

  • 在 Ubuntu WSL 中运行:
    docker --version  # 应显示版本号
    docker run hello-world  # 测试运行容器

    ✅ 如果命令成功,说明 Docker 已集成。


🌟 为什么能同时工作?

  • Docker Desktop 默认会将 Docker CLI 和守护进程(dockerd自动注入所有启用的 WSL 发行版
  • 实际容器仍在 docker-desktop WSL 中运行,但你在 Ubuntu WSL 中可以通过 docker 命令无缝操作。

⚠️ 常见问题排查

docker: command not found

  • 原因:未启用 WSL 集成或路径未配置。
  • 解决
    1. 确认 Docker Desktop 的 WSL 集成已启用(见上文)。
    2. 在 Ubuntu 中运行:
      echo "export PATH=$PATH:/mnt/c/Program Files/Docker/Docker/resources/bin" >> ~/.bashrc
      source ~/.bashrc

❌ 权限问题 Got permission denied

  • 原因:用户未加入 docker 组。
  • 解决
    sudo usermod -aG docker $USER
    newgrp docker  # 立即生效

📌 最佳实践建议

  1. 开发环境:在 Ubuntu WSL 中安装开发工具(如 nginxpython3),代码放在 WSL 文件系统内(如 ~/projects),避免 Windows 路径权限问题。
  2. 容器操作:直接在 Ubuntu WSL 中使用 docker 命令管理容器。
  3. 性能优化:将项目文件放在 WSL 内(如 /home/yourname/projects),而非 /mnt/c/(跨文件系统性能较差)。

🔄 两种 WSL 发行版的关系

发行版 用途 是否可删除?
Ubuntu 开发环境(安装软件、写代码) ❌ 不要删除
docker-desktop Docker 引擎后台运行 ⚠️ 删除会破坏 Docker

总结:方案 1(标准 WSL Ubuntu)和 Docker 完全兼容,只需在 Docker Desktop 设置中启用集成即可。你的 Ubuntu 会变成一个功能完整的开发环境,同时无缝操作 Docker 容器! 🐳🚀

Posted in Resourse | Leave a comment

被威联通的权限问题整哭了

运行下面的命令:grep httpdusr /etc/passwd
输出:httpdusr:x:99:0:Apache httpd user:/tmp:/bin/sh


根据你的 grep httpdusr /etc/passwd 输出,httpdusr 用户确实存在(UID=99,GID=0),但当你尝试 chown -R httpdusr:httpdusr 时仍然报错 unknown user/group。这可能是由于 httpdusr 的组(GID=0)被系统保留或未正确配置 导致的。
解决方案:直接使用 UID/GID 数字(推荐)
既然 httpdusr 的 UID=99、GID=0,可以改用数字形式。
sudo chown -R 99:0 /share/Web/wordpress


根据你的 ps aux | grep php-fpm 输出,可以看到:
PHP-FPM 主进程以 admin 用户运行
PHP-FPM 工作进程(实际处理请求的)以 httpdusr 用户运行


这种混合用户模式是导致权限问题的关键原因。以下是针对性解决方案:
终极解决方案
1. 统一文件所有权(关键步骤)
bash
复制
设置整个wordpress目录为httpdusr所有
sudo chown -R 99:0 /share/Web/wordpress
设置安全权限
sudo find /share/Web/wordpress -type d -exec chmod 755 {} \;
sudo find /share/Web/wordpress -type f -exec chmod 644 {} \;
特别设置wp-content可写
sudo chmod -R 775 /share/Web/wordpress/wp-content


但确实好了。发现其实就是要把主目录设置为httpusr,单目录设置是不行的,尤其是混合用户模式。

Posted in 网络相关 | Leave a comment

pip3 install pandas openpyxl 安装错误解决

[admin@NAS ~]# pip3 install pandas openpyxl
Collecting pandas
Could not fetch URL https://pypi.python.org/simple/pandas/: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] unknown error (_ssl.c:748) – skipping

这个错误通常是由于 SSL 证书验证失败导致的,可能是因为 Python 的 pip 工具无法验证 PyPI(Python 包索引)网站的 SSL 证书。你可以尝试以下几种解决方案:

解决方案
升级 pip:
确保你使用的是最新版本的 pip。可以通过以下命令升级:

复制
python3 -m pip install –upgrade pip
使用 –trusted-host 选项:
如果你信任 PyPI,可以在安装时添加 –trusted-host 选项:

复制
pip3 install –trusted-host pypi.python.org pandas openpyxl
检查系统时间:
确保你的系统时间和日期是正确的,不正确的系统时间可能导致 SSL 证书验证失败。

安装 CA 证书:
在某些情况下,可能需要安装或更新 CA 证书。你可以尝试以下命令:

复制
sudo apt-get install –reinstall ca-certificates
使用 HTTP 而不是 HTTPS(不推荐):
如果以上方法都无效,你可以临时使用 HTTP,但这会降低安全性:

复制
pip3 install –index-url=http://pypi.python.org/simple/ pandas openpyxl
其他建议
网络问题:
确保你的网络连接正常,有时网络问题也会导致 SSL 验证失败。

代理设置:
如果你在使用代理,确保代理设置正确。

Posted in 网络相关 | Leave a comment

qnap安装 Entware,通过entware安装python3 pip

在家中NAS系统Qnap上安装python,发现版本是2.7.18。于是通过威联通的APP Center安装3.12.6.1,结果python -V发现版本还是2.7.18,本想将就用吧。结果:
pip3 install pandas openpyxl
-sh: pip: command not found
郁闷了,pip也没有。于是一路apt-get,yum,dnf,apk安装器都没有。。真无语。
查看系统uname -a
Linux NAS 5.10.60-qnap #1 SMP Wed Jan 8 04:05:31 CST 2025 x86_64 GNU/Linux
发现没有Qnap系统下的安装器。真的抓狂了。好在还有deepseek,于是问了下:

The error -sh: ipkg: command not found indicates that the ipkg package manager is not installed on your QNAP NAS. ipkg is a lightweight package manager often used in embedded systems, but it is not included by default on all QNAP devices.

Here’s how you can proceed:


1. Install Entware (Recommended)

Entware is a modern package manager for embedded devices like QNAP NAS. It provides a wide range of precompiled software packages, including gcc, python3, and pip.

Steps to Install Entware:

  1. Enable SSH Access on Your QNAP NAS:

    • Log in to your QNAP web interface.
    • Go to Control Panel > Network & File Services > Telnet/SSH.
    • Enable SSH access and note the port number (default is 22).
  2. Connect to Your NAS via SSH:

    • Use an SSH client (e.g., ssh on Linux/macOS or PuTTY on Windows) to connect to your NAS:
      ssh admin@<your-nas-ip>
    • Replace <your-nas-ip> with the IP address of your NAS.
  3. Download and Run the Entware Installer:

    • Run the following commands to install Entware:
      wget -O - http://pkg.entware.net/binaries/x86-64/installer/entware_install.sh | /bin/sh
    • This script will download and install Entware on your NAS.
  4. Add Entware to Your PATH:

    • Add the following line to your shell profile (e.g., ~/.bashrc or ~/.profile):
      export PATH=/opt/bin:/opt/sbin:$PATH
    • Reload the profile:
      source ~/.bashrc
  5. Verify Entware Installation:

    • Check if opkg (the Entware package manager) is installed:
      opkg --version

2. Install Required Packages Using Entware

  • Update the package list:
     opkg update
  • Install gcc, python3, and pip:
     opkg install python3 python3-pip
  • Verify the installation:
     python3 --version
     pip3 --version

3. Install pandas and openpyxl

  • Use pip3 to install the required packages:
     pip3 install pandas openpyxl

4. Alternative: Manually Install Python

If you prefer not to use Entware, you can manually download and install Python 3.x from source. However, this requires a C compiler (gcc), which you may need to install manually.

Steps to Manually Install Python:

  1. Download Python Source Code:
      wget https://www.python.org/ftp/python/3.10.12/Python-3.10.12.tgz
  2. Extract and Build Python:
      tar -xvzf Python-3.10.12.tgz
      cd Python-3.10.12
      ./configure --enable-optimizations
      make
      sudo make install
  3. Verify Installation:
      python3 --version

5. Troubleshooting

  • If you encounter disk space issues, ensure you have enough storage on your NAS.
  • If you run into permission issues, use sudo or switch to the admin user.
  • If pip installation fails, try upgrading it:
     python3 -m pip install --upgrade pip

Let me know if you need further assistance! 😊

Posted in 网络相关 | Leave a comment

为服务器开启https访问

要开启 HTTPS 访问,你需要为你的域名配置 SSL 证书,并修改 Nginx 配置以支持 HTTPS。以下是具体步骤:


1. 获取 SSL 证书

推荐使用 Let’s Encrypt 免费 SSL 证书。你可以使用 certbot 工具来获取证书。

在主机A上安装 Certbot

sudo apt update
sudo apt install certbot

获取 SSL 证书

运行以下命令获取证书(确保域名已解析到主机A的IP地址):

sudo certbot certonly --standalone -d your-domain.com
  • your-domain.com 替换为你的实际域名。
  • 证书会保存在 /etc/letsencrypt/live/your-domain.com/ 目录下。

2. 修改 Nginx 配置文件

更新主机A上的 Nginx 配置文件,使其支持 HTTPS。

编辑之前创建的 reverse-proxy.conf 文件:

nano ~/nginx-proxy/conf.d/reverse-proxy.conf

修改为以下内容:

server {
    listen 80;
    server_name your-domain.com;
    return 301 https://$host$request_uri; # 将所有 HTTP 请求重定向到 HTTPS
}

server {
    listen 443 ssl;
    server_name your-domain.com;

    ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;

    location / {
        proxy_pass http://<服务器B的IP地址>:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

3. 修改 Docker Compose 文件

为了让 Nginx 容器能够访问主机上的 SSL 证书文件,需要将证书目录挂载到容器中。

编辑 docker-compose.yml 文件:

nano ~/nginx-proxy/docker-compose.yml

修改为以下内容:

version: '3'
services:
  nginx:
    image: nginx:latest
    container_name: nginx-proxy
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./conf.d:/etc/nginx/conf.d
      - /etc/letsencrypt:/etc/letsencrypt
    restart: always

4. 重启 Nginx 容器

更新配置后,重启 Nginx 容器以应用更改:

cd ~/nginx-proxy
docker-compose down
docker-compose up -d

5. 测试 HTTPS 访问

现在,你可以通过以下方式测试 HTTPS 是否正常工作:

  1. 访问 https://your-domain.com,确保能够正常加载服务器B的内容。
  2. 检查浏览器地址栏,确认显示为安全的 HTTPS 连接(小锁图标)。

6. 自动更新 SSL 证书(可选)

Let’s Encrypt 证书有效期为 90 天,需要定期更新。可以通过以下步骤设置自动更新。

手动测试更新

sudo certbot renew --dry-run

设置定时任务

编辑 crontab:

sudo crontab -e

添加以下内容,每天凌晨 2 点检查并更新证书:

0 2 * * * certbot renew --quiet --post-hook "docker restart nginx-proxy"

7. 防火墙配置

确保主机A的防火墙允许 HTTPS 流量(443 端口):

sudo ufw allow 443

总结

通过以上步骤,你已经成功配置了 HTTPS 访问:

  1. 使用 Let’s Encrypt 获取 SSL 证书。
  2. 修改 Nginx 配置以支持 HTTPS。
  3. 挂载 SSL 证书到 Docker 容器。
  4. 重启 Nginx 并测试 HTTPS 访问。

如果遇到问题,可以检查 Nginx 日志(docker logs nginx-proxy)或 Certbot 日志(/var/log/letsencrypt/)来排查问题。

Posted in 网络相关 | Tagged , , | Leave a comment

通过 Docker 部署 Nginx 并配置 HTTPS 反向代理

通过 Docker 部署 Nginx 并配置 HTTPS 反向代理,可以分为以下几个步骤:


1. 准备工作

  1. 获取 SSL 证书

    • 你可以从 Let’s Encrypt 或其他证书颁发机构获取免费的 SSL 证书。
    • 证书通常包括两个文件:
      • 证书文件(如 certificate.crt)。
      • 私钥文件(如 private.key)。
  2. 准备配置文件

    • 创建一个 Nginx 配置文件,用于定义反向代理和 HTTPS 配置。
  3. 安装 Docker

    • 确保你的服务器上已经安装了 Docker。如果没有安装,可以参考 Docker 官方文档

2. 创建 Nginx 配置文件

在宿主机上创建一个目录(如 /root/nginx),用于存放 Nginx 配置文件和 SSL 证书。

目录结构

/root/nginx/
├── nginx.conf
├── ssl/
│   ├── certificate.crt
│   └── private.key

Nginx 配置文件(nginx.conf

events {}

http {
    server {
        listen 80;
        server_name example.com;
        return 301 https://$host$request_uri;  # 将 HTTP 请求重定向到 HTTPS
    }

    server {
        listen 443 ssl;
        server_name example.com;

        ssl_certificate /etc/nginx/ssl/certificate.crt;  # SSL 证书路径
        ssl_certificate_key /etc/nginx/ssl/private.key;  # SSL 私钥路径

        ssl_protocols TLSv1.2 TLSv1.3;  # 支持的 SSL 协议版本
        ssl_ciphers HIGH:!aNULL:!MD5;   # 加密套件

        location / {
            proxy_pass http://backend-server:8080;  # 反向代理到后端服务
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }
}
  • 说明
    • listen 80:监听 HTTP 请求,并将其重定向到 HTTPS。
    • listen 443 ssl:监听 HTTPS 请求。
    • ssl_certificatessl_certificate_key:指定 SSL 证书和私钥的路径。
    • proxy_pass:将请求反向代理到后端服务(如 backend-server:8080)。

3. 运行 Nginx 容器

使用 Docker 运行 Nginx 容器,并将配置文件和 SSL 证书挂载到容器中。

运行命令

docker run -d \
  --name my-nginx \
  -p 80:80 \
  -p 443:443 \
  -v /root/nginx/nginx.conf:/etc/nginx/nginx.conf \
  -v /root/nginx/ssl:/etc/nginx/ssl \
  nginx
  • 参数说明
    • -d:以后台模式运行容器。
    • --name my-nginx:为容器命名为 my-nginx
    • -p 80:80:将宿主机的 80 端口映射到容器的 80 端口(HTTP)。
    • -p 443:443:将宿主机的 443 端口映射到容器的 443 端口(HTTPS)。
    • -v /root/nginx/nginx.conf:/etc/nginx/nginx.conf:挂载 Nginx 配置文件。
    • -v /root/nginx/ssl:/etc/nginx/ssl:挂载 SSL 证书目录。
    • nginx:使用官方 Nginx 镜像。

4. 测试访问

  1. HTTP 测试

    • 访问 http://example.com,应该会自动重定向到 https://example.com
  2. HTTPS 测试

    • 访问 https://example.com,确保页面正常加载,并且浏览器显示安全连接(锁图标)。
  3. 后端服务测试

    • 确保后端服务(如 backend-server:8080)正常运行,并且可以通过 Nginx 反向代理访问。

5. 其他注意事项

  1. 证书更新

    • 如果使用 Let’s Encrypt 证书,证书有效期为 90 天,需要定期更新。
    • 更新证书后,重启 Nginx 容器以加载新证书:
      docker restart my-nginx
  2. 防火墙配置

    • 确保服务器的防火墙允许 80(HTTP)和 443(HTTPS)端口的流量。
  3. 日志查看

    • 如果遇到问题,可以查看 Nginx 容器的日志:
      docker logs my-nginx
  4. 性能优化

    • 可以根据需要调整 Nginx 的 SSL 配置(如启用 HTTP/2、优化加密套件等)。

6. 总结

通过 Docker 部署 Nginx 并配置 HTTPS 反向代理的步骤如下:

  1. 准备 SSL 证书和 Nginx 配置文件。
  2. 使用 Docker 运行 Nginx 容器,挂载配置文件和证书。
  3. 测试 HTTP 和 HTTPS 访问,确保反向代理正常工作。

如果你有其他问题,欢迎随时提问!

Posted in 网络相关 | Tagged , , | Leave a comment

多应用共享80端口解决方案(探讨docker compose 有点)

直接在宿主机上配置Nginx确实可以解决问题。然而,使用Docker Compose结合Nginx容器化的方式有一些额外的优势,具体取决于你的需求和场景。以下是两者的对比以及使用Docker Compose的意义:


1. 直接在宿主机上配置Nginx

  • 优点

    • 简单直接,不需要额外的Docker容器。
    • 适合小型项目或不需要复杂容器化管理的场景。
    • 性能稍高,因为没有额外的容器化开销。
  • 缺点

    • 与宿主机环境耦合,迁移或扩展时需要手动调整配置。
    • 如果宿主机环境发生变化(如操作系统升级),可能影响Nginx的运行。
    • 不方便与其他容器化服务统一管理。

2. 使用Docker Compose结合Nginx容器化

  • 优点

    • 环境隔离:Nginx和其他应用都在容器中运行,与宿主机环境解耦,避免依赖冲突。
    • 可移植性:整个服务栈(Nginx + 应用)可以通过docker-compose.yml一键部署到任何支持Docker的环境中。
    • 统一管理:所有服务(Nginx、公司站点、PDF工具等)可以通过Docker Compose统一管理,方便启动、停止和扩展。
    • 版本控制:Nginx配置和Docker Compose文件可以纳入版本控制,方便团队协作和回滚。
    • 扩展性:如果需要添加更多服务(如数据库、缓存等),可以直接在docker-compose.yml中定义,无需额外配置宿主机。
  • 缺点

    • 稍微复杂一些,需要编写docker-compose.yml和Nginx配置文件。
    • 有一定的容器化开销(性能影响通常可以忽略)。

3. 使用Docker Compose的意义

如果你已经使用Docker来运行应用,那么将Nginx也容器化并与Docker Compose结合,可以带来以下好处:

  1. 一致性:所有服务(包括Nginx)都在容器中运行,保持环境一致性。
  2. 简化部署:通过docker-compose up -d即可启动整个服务栈,无需手动配置宿主机。
  3. 易于扩展:如果需要添加更多服务或调整配置,只需修改docker-compose.yml和Nginx配置文件,然后重新启动服务。
  4. 适合CI/CD:Docker Compose可以轻松集成到持续集成/持续部署(CI/CD)流程中,实现自动化部署。

4. 示例:Docker Compose + Nginx

以下是一个完整的docker-compose.yml示例,展示如何将Nginx和其他应用容器化并通过反向代理提供服务:

version: '3'
services:
  # 公司站点应用
  company-site:
    image: your-company-site-image
    ports:
      - "3000:3000"  # 内部端口3000

  # PDF在线转换工具
  pdf-tool:
    image: your-pdf-tool-image
    ports:
      - "4000:4000"  # 内部端口4000

  # Nginx反向代理
  nginx:
    image: nginx:latest
    ports:
      - "80:80"  # 对外暴露80端口
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf  # 挂载Nginx配置文件
    depends_on:
      - company-site
      - pdf-tool

Nginx配置文件(nginx.conf

events {}

http {
    server {
        listen 80;
        server_name company.com;

        location / {
            proxy_pass http://company-site:3000;  # 指向公司站点容器
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }

    server {
        listen 80;
        server_name tools.company.com;

        location / {
            proxy_pass http://pdf-tool:4000;  # 指向PDF工具容器
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }
}

启动服务

docker-compose up -d

5. 总结

  • 如果你只需要简单部署,直接在宿主机上配置Nginx是更直接的选择。
  • 如果你需要环境隔离、可移植性和统一管理,使用Docker Compose结合Nginx容器化是更好的选择。

最终选择取决于你的具体需求和项目规模。如果你的应用已经容器化,并且未来可能扩展或迁移,推荐使用Docker Compose的方式。

Posted in 网络相关 | Tagged , | Leave a comment

多应用共享80端口解决方案)

要解决多个应用通过80端口对外提供服务的问题,可以使用反向代理服务器(如Nginx或Apache)来管理流量。以下是具体步骤:

1. 使用反向代理服务器

反向代理服务器可以根据请求的域名或路径将流量分发到不同的内部端口。

使用Nginx作为反向代理

  1. 安装Nginx

    sudo apt-get update
    sudo apt-get install nginx
  2. 配置Nginx
    编辑Nginx配置文件(通常位于/etc/nginx/sites-available/default/etc/nginx/nginx.conf),添加以下内容:

    server {
       listen 80;
       server_name company.com;
    
       location / {
           proxy_pass http://localhost:3000;  # 公司站点应用的内部端口
           proxy_set_header Host $host;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header X-Forwarded-Proto $scheme;
       }
    }
    
    server {
       listen 80;
       server_name tools.company.com;
    
       location / {
           proxy_pass http://localhost:4000;  # PDF在线转换工具的内部端口
           proxy_set_header Host $host;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header X-Forwarded-Proto $scheme;
       }
    }

    这里假设:

    • company.com 是公司站点的域名,映射到3000端口。
    • tools.company.com 是在线工具的域名,映射到4000端口。
  3. 重启Nginx

    sudo systemctl restart nginx

使用Apache作为反向代理

  1. 安装Apache

    sudo apt-get update
    sudo apt-get install apache2
  2. 启用代理模块

    sudo a2enmod proxy
    sudo a2enmod proxy_http
  3. 配置Apache
    编辑Apache配置文件(通常位于/etc/apache2/sites-available/000-default.conf),添加以下内容:

    <VirtualHost *:80>
       ServerName company.com
    
       ProxyPreserveHost On
       ProxyPass / http://localhost:3000/
       ProxyPassReverse / http://localhost:3000/
    </VirtualHost>
    
    <VirtualHost *:80>
       ServerName tools.company.com
    
       ProxyPreserveHost On
       ProxyPass / http://localhost:4000/
       ProxyPassReverse / http://localhost:4000/
    </VirtualHost>
  4. 重启Apache

    sudo systemctl restart apache2

2. 使用Docker Compose

如果使用Docker Compose管理容器,可以在docker-compose.yml中定义服务并通过Nginx或Apache进行反向代理。

version: '3'
services:
  web:
    image: your-company-site-image
    ports:
      - "3000:3000"
  pdf-tool:
    image: your-pdf-tool-image
    ports:
      - "4000:4000"
  nginx:
    image: nginx
    ports:
      - "80:80"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
    depends_on:
      - web
      - pdf-tool

3. DNS配置

确保域名解析正确:

  • company.com 指向服务器IP。
  • tools.company.com 也指向服务器IP。

总结

通过反向代理服务器(如Nginx或Apache),你可以将多个应用通过80端口对外提供服务,并根据域名或路径将流量分发到不同的内部端口。

Posted in 网络相关 | Tagged , | Leave a comment

推荐几个wordpress下的markdown格式发布插件

WP Githuber MD 插件因安全问题已关闭,我们可以选择其他可靠的Markdown插件来替代。以下是几个推荐的Markdown插件:


推荐替代插件

  1. Jetpack(由Automattic开发)

    • Jetpack 是一个多功能插件,其中包含Markdown支持。
    • 下载地址:Jetpack on WordPress.org
    • 安装后,启用“Markdown”模块即可使用。
  2. WP-Markdown

  3. Markdown Editor

  4. Easy Markdown


安装步骤

方法一:通过WordPress后台安装

  1. 登录WordPress后台。
  2. 进入“插件” > “安装插件”。
  3. 在搜索框中输入插件名称(如“Jetpack”或“WP-Markdown”)。
  4. 找到插件后,点击“安装”,然后点击“激活”。

方法二:手动下载并安装

  1. 访问插件的WordPress页面(如上面的下载地址)。
  2. 下载插件的ZIP文件。
  3. 登录WordPress后台,进入“插件” > “安装插件” > “上传插件”。
  4. 上传ZIP文件并激活。

注意事项

  1. 备份网站:在安装新插件前,建议备份你的网站数据和数据库。
  2. 兼容性:确保插件支持WordPress 4.9.26版本。如果不确定,可以在插件的WordPress页面查看兼容性信息。
  3. 安全性:选择官方推荐的插件,避免使用来源不明的插件,以防止安全问题。
Posted in 网络相关 | Tagged | Leave a comment

如何让wordpress支持markdown格式的文章发布

要让WordPress支持Markdown格式的文章发布,可以按照以下步骤操作:

方法一:使用插件

  1. 安装Markdown插件

    • 登录WordPress后台,进入“插件” > “安装插件”。
    • 搜索“Markdown”插件,如“Jetpack”或“WP Githuber MD”。
    • 安装并激活插件。
  2. 配置插件

    • 激活后,进入插件设置页面,启用Markdown支持。
    • 部分插件可能需额外配置,如“WP Githuber MD”允许在文章编辑器中直接使用Markdown语法。

方法二:手动添加Markdown支持

  1. 编辑主题文件

    • 通过FTP或文件管理器,找到当前主题的functions.php文件。
    • 在文件末尾添加以下代码:
      php
      function enable_markdown_for_posts() {
      add_post_type_support( 'post', 'markdown' );
      }
      add_action( 'init', 'enable_markdown_for_posts' );
  2. 使用Markdown解析库

    • 下载并安装Markdown解析库,如Parsedown。
    • 将库文件上传到主题目录,并在functions.php中引入:
      php
      require_once get_template_directory() . '/parsedown/Parsedown.php';
  3. 在主题中解析Markdown

    • 修改主题模板文件,使用Parsedown解析Markdown内容:
      php
      $parsedown = new Parsedown();
      echo $parsedown->text( get_the_content() );

方法三:使用Markdown编辑器

  1. 安装Markdown编辑器插件
    • 搜索并安装Markdown编辑器插件,如“WP Editor.md”或“Markdown Editor”。
    • 安装后,激活插件即可在文章编辑器中使用Markdown格式。

注意事项

  • 备份:修改主题文件前,务必备份。
  • 插件冲突:某些插件可能与Markdown插件冲突,需测试兼容性。
  • 主题支持:部分主题可能不支持Markdown,需手动调整。

通过这些步骤,WordPress即可支持Markdown格式的文章发布。

Posted in 生活 | Leave a comment