首页 > 解决方案 > Nginx+php-fpm。静态网站 + WordPress

问题描述

请帮帮我。

我有包含 2 个站点的文件夹example.com 。WP 文件夹中的 WordPress 站点和根目录中的 100 多个静态页面。我应该将 WP 移到“StaticPages”文件夹中的根目录、静态页面中。

我有 nginx 配置:

server {
    listen  80;
    server_name example.local www.example.local;
    rewrite ^/(.*) https://www.example.local/$1 permanent;
}

server {
    listen  443 ssl;
    server_name example.local;
    rewrite ^/(.*) https://www.example.local/$1 permanent;
    ssl_certificate /etc/nginx/ssl/example.crt;
    ssl_certificate_key /etc/nginx/ssl/example.key;
}

server {
    listen     443 ssl;
    server_name www.example.local;
    root /home/stanislav/Documents/projects/example.com;
    rewrite_log on;

    index index.html index.php;

    if ($request_uri = /index.html) {
        return 301 $scheme://$host/;
    }

    if ($request_uri = /index.php) {
        return 301 $scheme://$host/;
    }

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

    location ~ \.(php|htm|html|phtml)$  {
    try_files $uri $uri/ /wp/index.php?$args;
    ####
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    set $path_info $fastcgi_path_info;
    fastcgi_param PATH_INFO $path_info;
    fastcgi_index index.php;
    include fastcgi.conf;
    fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    ####
    }

    location ~ /\. {
        deny all;
    }

   location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf|woff|eot|ttf|pdf|mp4|exe|doc|html|flv|ico|xml|txt|css|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
       access_log off;
       log_not_found off;
       expires max; # static cache
    }

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

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

    access_log /var/log/nginx/example.log;
    error_log /var/log/nginx/example.log;

    ssl_certificate /etc/nginx/ssl/example.crt;
    ssl_certificate_key /etc/nginx/ssl/example.key;
}

搬家后,我想像这样打开我的静态页面。

example.com/mystaticpage.html

我想像这样打开我的wordpress页面。

example.com/mywppage.html

URL 中没有文件夹名称但我不明白如何为此创建路由器?

标签: phpwordpressnginx

解决方案


推荐阅读