nginx - reverse proxy java and wordpress

0

On a Centos 7 host, I have 2 Java http servers and a Wordpress site.

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {

        listen       443 ssl http2;
        listen       [::]:443 ssl http2;
        ssl_certificate     /etc/nginx/ssl/fanpaper-tld-cert.pem;
        ssl_certificate_key     /etc/nginx/ssl/fanpaper-tld-key.pem;

        server_name  fanpaper.ir www.fanpaper.ir;

        root    /root/blogs/fanpaperblog;

        index index.php index.html index.htm index.nginx-debian.html;

        #location = /favicon.ico { log_not_found off; access_log off; }
        #location = /robots.txt { log_not_found off; access_log off; allow all; }

        location /blog {
            try_files $uri $uri/ /blog/index.php?q=$1;
        }


        # Load configuration files for the default server block.
        #include /etc/nginx/default.d/*.conf;

        location / {
        proxy_pass http://localhost:8085/;
        }
        location /shop {
            proxy_pass http://localhost:8086/;
        }

        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
        location ~ /\.ht {
            deny all;
        }
        #error_page 404 /404.html;
        #    location = /40x.html {
        #}

        #error_page 500 502 503 504 /50x.html;
        #    location = /50x.html {
        #}
    }

}

The two Java sites are being served correctly at /shop and /, however the test.php file under /root/blogs/fanpaperblog/ is not being served correctly.

When I open the url http://fanpaper.ir/blog/test.php, I get 404.

error_log reports nothing access_log says the request was served correctly( with the response of 404).

Mohsen Salahshoor

Posted 2019-06-10T07:09:06.350

Reputation: 223

Just a comment, but you seem to be serving files from outside the directory root. This can be potentially problematic depending on permissions, etc. – Anaksunaman – 2019-06-13T21:24:23.047

No answers