3

wordpress | 如何在 wordpress 服务器上运行其他独立站点

 1 month ago
source link: https://benpaodewoniu.github.io/2024/03/30/wordpress18/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

在 wordpress 中运行其他独立站点。

此时,我的 wordpress 采用的是多站点模式。

关于多站点,可以参考我的相关博客。

独立站点有很多种

  • 前后端分离

前后端分离

如果是前后端分离的话,也就是只有 html 文件,那么,无论是子目录还是子域名都能很好的集成。

子目录的话,就是

server {
listen 80;
server_name thlm.com;
listen 443 ssl default_server;
listen [::]:443 ssl default_server;#新增这两个
ssl_certificate /home/ubuntu/httpAll/fullchain.crt;
ssl_certificate_key /home/ubuntu/httpAll/private.pem;

root /var/www/wordpress; # wordpress 的放置路径
index index.php;

...

location /lumi {
alias /var/www/wordpress/Static/lumi;
index index.html;
try_files $uri $uri/ /Static/lumi/index.html;
}
}

/lumi 通过 alias 重定向就可以了。

子域名就不说了。

比如 index.php 这一类。

这一类的话,用子目录就不行了,因为,作为一个网站,它需要绑定 php 服务器,也就是它需要自己绑定一个端口。「ps:我并没有在 80 端口下成功运行 wordpress 和 独立站,或许有解决方案,但是,我没试出来」

假设,index.php 绑定 8088 端口,即单独弄一个 server,那么,通过反向代理,比如

proxy_pass 127.0.0.1:8089;
...

也是满足不了的。

  • 这样反向代理,会导致如果跳转的话会带 8088 端口,如果不跳转(即 url 不显示 8088 ),那么资源文件访问不了,毕竟这个网站端口都绑定在 8088
    • xxx.com:8088/assert/a.png 返回 200
    • xxx.com/assert/a.png 返回 404
    • 或许反向代理有更优雅或者真的能行,但是,我还是没尝试出来

最后,如果采用重定向,直接返回 xxx.com:8088 ,说实话太丑了。

但是,如果使用子域名就完美解决这件事。

因为,同一端口可以绑定不同的子域名,然后访问不同的服务,相关的参考资料如下

这里写一个 nginx 的配置。

# Upstream to abstract backend connection(s) for php
upstream php {
server unix:/run/php/php7.4-fpm.sock;
}


server {
listen 80;
server_name thlm.com;
listen 443 ssl default_server;
listen [::]:443 ssl default_server;#新增这两个
ssl_certificate /home/ubuntu/httpAll/fullchain.crt;
ssl_certificate_key /home/ubuntu/httpAll/private.pem;

root /var/www/wordpress; # wordpress 的放置路径
index index.php;

location = /favicon.ico {
log_not_found off;
access_log off;
}

location /Static/lumi {
alias /var/www/wordpress/Static/lumi;
index index.html;
try_files $uri $uri/ /Static/lumi/index.html;
}

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

location /lumi/Extend {
alias /var/www/wordpress/Extend/;
}


location / {
try_files $uri $uri/ /index.php?$args;
}

location /lumi{
return 301 https://lumi.thlm.com$request_uri;
}

location ~ \.php$ {
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found on;
}
rewrite ^/([_0-9a-zA-Z-]+/)?wp-admin$ /$1wp-admin/ permanent;

if (-f $request_filename){
set $rule_2 1;
}
if (-d $request_filename){
set $rule_2 1;
}
if ($rule_2 = "1"){
}
rewrite ^/([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) /$2 last;
rewrite ^/([_0-9a-zA-Z-]+/)?(.*.php)$ /$2 last;
rewrite ^/(?!Extend|Static)(.*)$ /index.php?$1 last;
}

server {
listen 80;
server_name thlm.thlm.com;
listen 443 ssl;
listen [::]:443 ssl;#新增这两个
ssl_certificate /home/ubuntu/httpAll/fullchain.crt;
ssl_certificate_key /home/ubuntu/httpAll/private.pem;
root /var/www/wordpress/Static/thlm/;

location / {
try_files $uri $uri/ /index.php?$args;
index index.php;
}

location ~ \.php$ {
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK