繁体   English   中英

子文件夹和别名中带有 wordpress 的 Nginx 配置

[英]Nginx config with wordpress in a subfolder and alias

我有一个非常奇怪的 nginx 设置。 我需要以下设置:

  • url "/" -> /srv/www/landing-pages 中的静态 html 文件

  • url "/tr_tr/blog/*" -> wordpress 安装在 /srv/www/domain.com

  • url "/en_us/blog/*" -> wordpress 安装在 /srv/www/domain.com

wordpress 配置就像

  • 目前,wordpress 安装被配置为回答 domain.com。
  • 整个 /tr_tr/blog 结构是用 wpml 多语言插件构建的。
  • 两个 wordpress 页面是用 "/blog" slug 创建的,并以 wpml 插件的语言环境为前缀。
  • 博客文章永久链接设置为 /blog/%postname%-%post_id%/ 这些永久链接也自动以 wpml 的语言环境为前缀。

我的nginx配置是

server {
    server_name www.domain.com;
    return 301 $scheme://domain.com$request_uri;
}
server {
    listen 80;
    listen [::]:80;

    server_name domain.com;
    return 301 https://$server_name$request_uri;
}
server {
    listen   443 ssl;
    server_name domain.com;

    gzip on;
    gzip_proxied any;
    gzip_types
        text/plain
        text/xml
        text/css
        image/svg+xml
        application/json
        application/javascript
        application/x-javascript;
    gzip_vary on;
    gzip_disable “MSIE [1-6]\.(?!.*SV1)”;

    expires $expires;

    ssl_certificate /etc/nginx/ssl/fullchain.pem;
    ssl_certificate_key /etc/nginx/ssl/privkey.pem;

    server_tokens off;

#    include /etc/nginx/nginx-wp-common.conf;

location / {
  root /srv/www/landing-pages;
  index index.html index.htm;
  try_files $uri $uri/ /$uri;
}

location /tr_tr/blog {
  alias /srv/www/domain.com/;
  index index.php;
  try_files $uri $uri/ /index.php?$args =404;

  location ~ \/tr_tr\/blog\/.*\.php$ {
    try_files $uri =404;
    include /etc/nginx/fastcgi_params;
    fastcgi_read_timeout 3600s;
    fastcgi_param SCRIPT_FILENAME /srv/www/domain.com/$fastcgi_script_name;
    fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_index index.php;
  }

 }
}

我在开发过程中只添加了 tr_tr 位置。 目前,我正在为博客 url 获取 404 的 403 的“未指定输入文件”。

根 url 很好,我可以在 domain.com/test.html 的 srv/www/landing-pages 文件夹中打开我的虚拟 html 文件

这个想法是,

  • 所有网址都应遵循 /{locale}/{project} 模板。
  • 公司登陆页面将从登陆页面文件夹(gatsbyjs)提供
  • 公司博客来自 /{locale}/blog urls
  • 我不想为这两个国家创建两个单独的 wp 安装。

如何在 nginx 中设置此配置?

好的! 这是场景(我的情况):

  • symfony:/var/www/mysite.com
  • wp:/var/www/blog.mysite.com

这就是您访问的方式(替换 mysite 的示例,因为验证)

这是我的 default.conf

server {
    server_name mysite.com;
    root /var/www/mysite.com/web;

    location @wp {
        rewrite ^/blog(.*) /blog/index.php?q=$1;
    }

    location ^~ /blog {
        alias /var/www/blog.mysite.com;
        index index.php;
        try_files $uri $uri/ @wp;

        location ~ \.php$ {
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            fastcgi_pass unix:/run/php/php-fpm.sock;
        }
    }

    location / {
        try_files $uri /app.php$is_args$args;
    }

    location ~ ^/app\.php(/|$) {
        fastcgi_pass unix:/run/php/php-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        internal;
    }

    location ~ \.php$ {
        return 404;
    }

    listen 443 ssl http2; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/mysite.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mysite.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
    if ($host = mysite.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    server_name mysite.com;
    listen 80;
    return 404; # managed by Certbot
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM