I have three requirements from my Nginx setup:
- Forward all requests on / to my Java server running on port 9001
- Intercept all static file URLs and serve them through Nginx itself.
- Serve a particular base URL from a folder containing PHP scripts.
Of these, I'm able to achieve the first two, but when I visit http://localhost/ecwid_fu_scripts/
through my web browser, the request is intercepted by the Java server running on port 9001, and doesn't get routed to the index.php
in /home/ankush/ecwid_fu_scripts/
. Here's my Nginx configuration:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
location /assets/images/ {
root /home/ankush/fu_main_files/;
autoindex off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 100;
}
location /ecwid_fu_scripts/ {
index index.php;
root /home/ankush/ecwid_fu_scripts/;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location / {
proxy_pass http://localhost:9001;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}