1

I have nginx proxying to apache as a backend in order for nginx to handle static assets. Unfortunately when I attempt to visit main domain it just displays page not found. I get 404 error for these files.

example.com > page not found

example.com/somepage/ > works but web server isn't loading css and js files.

My Nginx config:

server {
    listen 80;
    server_name example.com www.example.com;
    root /home/wpaper/public_html;
    index index.php index.htm index.html;
#    include /home/wpaper/public_html/nginx.conf;

    location / {
        try_files $uri $uri/ @proxy;
    }

    location @proxy {
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $host;
    proxy_pass http://127.0.0.1:8081;
}

    location ~ (index|get|static|report|404|503|health_check)\.php$ {
    try_files $uri =404;
    proxy_buffering off;
    proxy_pass http://127.0.0.1:8081;
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Client-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}

    location ~ \.php$ {
        proxy_pass http://127.0.0.1:8081;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
}


    location ~ /\.ht {
        deny all;
    }
}

As you can see Apache is listening to 8081 port.

Here is its virtual host

<VirtualHost 127.0.0.1:8081>
        ServerName example.com
        ServerAlias www.example.com
        DocumentRoot /home/wpaper/public_html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <Directory /home/wpaper/public_html>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Require all granted
        </Directory>
    </VirtualHost>

.htaccess for root folder

DirectoryIndex index.php php_flag session.auto_start off SecFilterEngine Off SecFilterScanPOST Off

SSLOptions StdEnvVars

Options +FollowSymLinks
RewriteEngine on

#RewriteBase /magento/

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
RewriteRule .* - [L,R=405]


#RewriteCond %{REQUEST_URI} !^/mobiledirectoryhere/.*$
#RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
#RewriteRule ^(.*)$ /mobiledirectoryhere/ [L,R=302]


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule .* index.php [L]

AddDefaultCharset Off
#AddDefaultCharset UTF-8
AddType 'text/html; charset=UTF-8' html

ExpiresDefault "access plus 1 year"
ExpiresByType text/html A0
ExpiresByType text/plain A0

Header set X-UA-Compatible "IE=edge"

# `mod_headers` cannot match based on the content-type, however,
# the `X-UA-Compatible` response header should be send only for
# HTML documents and not for the other resources.

<FilesMatch "\.(appcache|atom|bbaw|bmp|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|topojson|tt[cf]|txt|vcard|vcf|vtt|webapp|web[mp]|webmanifest|woff2?|xloc|xml|xpi)$">
    Header unset X-UA-Compatible
</FilesMatch>

Any help please because I not very familiar with these.

0

You must log in to answer this question.

Browse other questions tagged .