3

I have a pretty weird nginx setup. I need the following setup:

  • url "/" -> static html files in /srv/www/landing-pages

  • url "/tr_tr/blog/*" -> wordpress installation in /srv/www/domain.com

  • url "/en_us/blog/*" -> wordpress installation in /srv/www/domain.com

The wordpress configuration is like

  • currently the wordpress installation is configured to answer to domain.com.
  • the whole /tr_tr/blog structure is constructed with wpml multi language plugin.
  • two wordpress pages are created with "/blog" slug and are prefixed with locales by the wpml plugin.
  • Blog post permalinks are set to /blog/%postname%-%post_id%/ Those permalinks are prefixed with locales by wpml automatically too.

My nginx configuration is

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;
  }

 }
}

I added only tr_tr location during development. Currently I'm getting 404's 403's "No input file specified's" for blog urls.

Root urls are fine, I can open my dummy html files in srv/www/landing-pages folder from domain.com/test.html

The idea is,

  • all urls should follow /{locale}/{project} template.
  • corporate landing pages will be served from landing-pages folder (gatsbyjs)
  • Company blog is served from /{locale}/blog urls
  • I dont want to create two seperate wp installations for both countries.

How can I setup this configuration in nginx?

1 Answer 1

1

Ok! This is the scenario (my case):

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

And this is how you access (replace example for mysite because validation)

This is my 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
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.