CWP - NGINX & Varnish & Apache with PHP-FPM server do no rewrite in subdomain only



  • Hi

    Need some help for server with Nginx & Varnish & Apache & php-fpm.

    The server "CWP" works fine with WordPress permalink like maindomain.com/postname/ URL format but for sub.domain.com/postname/ return 404 error; Subdomain only works with "sub.domain.com/?p=123" URL format

    There are not error in Nginx log. The only error is in apache /usr/local/apache/domlogs/sub.domain.com.error.log

    2020/03/28 14:05:16 [error] 23586#23586: *12500 "/home/user/sub.domain.com/hello-world/index.php" is not found (2: No such file or directory), client: xxx.xxx.xx.xx, server: sub.domain.com, request: "GET /hello-world/ HTTP/1.1", host: "sub.domain.com", referrer: "http://sub.domain.com/"
    

    Settings information below:

    The Nginx conf default (generated by server admin panel):

    server {
        listen 186.192.120.36:80;   
        server_name 186.192.120.36;
        access_log /usr/local/apache/domlogs/186.192.120.36.bytes bytes;
        access_log /usr/local/apache/domlogs/186.192.120.36.log combined;
        error_log /usr/local/apache/domlogs/186.192.120.36.error.log error;
    
        location / {
            location ~.*\.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|woff|ttf|svg|eot|sh)$ {
                root /usr/local/apache/htdocs/;                     
                expires max;
                try_files $uri @backend;
            }
    
            location ~ ^/~(.+?)(/.*)?$ {
                internal;
                proxy_pass http://186.192.120.36:8181;
                include proxy.inc;
            }
    
            error_page 405 = @backend;
            error_page 500 = @custom;
            add_header X-Cache "HIT from Backend";
            proxy_pass http://186.192.120.36:8181;
            include proxy.inc;
        }
    
        location @backend {
            internal;
            proxy_pass http://186.192.120.36:8181;
            include proxy.inc;
        }
    
        location @custom {
            internal;
            proxy_pass http://186.192.120.36:8181;
            include proxy.inc;
        }
    
        location ~ .*\.(php|jsp|cgi|pl|py)?$ {
            proxy_pass http://186.192.120.36:8181;
            include proxy.inc;
        }
    
        location ~ /\.ht    {deny all;}
        location ~ /\.svn/  {deny all;}
        location ~ /\.git/  {deny all;}
        location ~ /\.hg/   {deny all;}
        location ~ /\.bzr/  {deny all;}
    
        disable_symlinks if_not_owner from=/usr/local/apache/htdocs/;
    
        location /.well-known/acme-challenge {
            default_type "text/plain";
            alias /usr/local/apache/autossl_tmp/.well-known/acme-challenge;
        }
    
    }
    

    The Nginx vhost sub.domain.com.conf (generated by server admin panel):

    server {
        listen 186.192.120.36:80;   
        server_name sub.domain.com  www.sub.domain.com;
        root /home/user/sub.domain.com;
        index index.php index.html index.htm;
        access_log /usr/local/apache/domlogs/sub.domain.com.bytes bytes;
        access_log /usr/local/apache/domlogs/sub.domain.com.log combined;
        error_log /usr/local/apache/domlogs/sub.domain.com.error.log error;
    
        location / {
    
            location ~.*\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {          
                expires max;
            }
    
            location ~ [^/]\.php(/|$) {
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                if (!-f $document_root$fastcgi_script_name) {
                    return  404;
                }
    
                fastcgi_pass    unix:/opt/alt/php-fpm73/usr/var/sockets/user.sock;
                fastcgi_index   index.php;
                include         /etc/nginx/fastcgi_params;
            }
    
        }
    
        location ~* "/\.(htaccess|htpasswd)$" {deny all;return 404;}
    
        disable_symlinks if_not_owner from=/home/user/sub.domain.com;
    
        location /.well-known/acme-challenge {
            default_type "text/plain";
            alias /usr/local/apache/autossl_tmp/.well-known/acme-challenge;
        }
    }
    

    This is the Apache vhost for sub.domain.com:

    <VirtualHost 186.192.120.36:8181>
        ServerName sub.domain.com
        ServerAlias sub.domain.com
        ServerAdmin webmaster@sub.domain.com
        DocumentRoot /home/user/sub.domain.com
        UseCanonicalName Off
        ScriptAlias /cgi-bin/ /home/user/sub.domain.com/cgi-bin/
    
        #CustomLog /usr/local/apache/domlogs/sub.domain.com.bytes bytes
        #CustomLog /usr/local/apache/domlogs/sub.domain.com.log combined
        ErrorLog /usr/local/apache/domlogs/sub.domain.com.error.log
    
        # Custom settings are loaded below this line (if any exist)
        # IncludeOptional "/usr/local/apache/conf/userdata/user/sub.domain.com/*.conf"
    
        <IfModule mod_setenvif.c>
            SetEnvIf X-Forwarded-Proto "^https$" HTTPS=on
        </IfModule>
    
        <IfModule mod_userdir.c>
            UserDir disabled
            UserDir enabled user
        </IfModule>
    
        <IfModule mod_suexec.c>
            SuexecUserGroup user user
        </IfModule>
    
        <IfModule mod_suphp.c>
            suPHP_UserGroup user user
            suPHP_ConfigPath /home/user
        </IfModule>
    
        <IfModule mod_ruid2.c>
            RMode config
            RUidGid user user
        </IfModule>
    
        <IfModule itk.c>
            AssignUserID user user
        </IfModule>
    
        <Directory "/home/user/sub.domain.com">
            Options -Indexes -FollowSymLinks +SymLinksIfOwnerMatch
            AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
        </Directory>
    
        <IfModule proxy_fcgi_module>
            <FilesMatch \.php$>
                SetHandler "proxy:unix:/opt/alt/php-fpm73/usr/var/sockets/user.sock|fcgi://localhost"
            </FilesMatch>
        </IfModule>
    
    
    </VirtualHost>
    

    Both sites (main.com and subdomain.com) have .htaccess file:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress
    

    Any suggestion?

    Thanks in advance



  • @Ricardo-Santos said in CWP - NGINX & Varnish & Apache with PHP-FPM server do no rewrite in subdomain only:

    root

    hi did you changed the permalink settings under wordpress ?


Log in to reply
 

Recent Topics