php - Nginx + php5-fpm = 404 Error with alias location -
i amateur front end web developer, , bought ubuntu server try hand @ backend development. trying figure out how serve php file aliased location block using php5-fpm. getting 404 - page not found error. have tried of proposed solutions find here no luck. still beginner love quick eli5 , pointers on rest of conf file, can learn too. should mention main root folder running flask app, , reason using aliased location.
my virtual host:
nginx conf file
server { listen 80; listen [::]:80; server_name www.example.com example.com; root /var/www/example; large_client_header_buffers 8 32k; access_log /var/www/example/logs/access.log; error_log /var/www/example/logs/error.log; location / { proxy_http_version 1.1; proxy_set_header upgrade $http_upgrade; proxy_set_header connection "upgrade"; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $remote_addr; #$proxy_add_x_forwarded_for; proxy_set_header host $http_host; proxy_set_header x-nginx-proxy true; proxy_pass http://app_test; proxy_redirect off; } location /test_site { alias /var/www/test_site; index index.php index.html index.htm; location ~ .php$ { try_files $uri =404; fastcgi_split_path_info ^(.+?\.php)(/.*)?$; fastcgi_pass unix:127.0.0.1:9000; fastcgi_index index.php; include fastcgi_params; } }
php5 www.conf file
[www] ... user = www-data group = www-data listen = 127.0.0.1:9000 #listen = /tmp/php5-fpm.sock listen.owner = www-data listen.group = www-data listen.mode = 0660 ...
my fastcgi_params file default. have checked both php , nginx logs , there no errors. appreciated!
getting alias
work nested locations using fastcgi
complicated.
assuming have not on simplified configuration, test_site
location not need use alias
:
location /test_site { root /var/www; index index.php index.html index.htm; location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:127.0.0.1:9000; include fastcgi_params; } }
this removes alias
directive, , solves aliasing problem in php block.
note also: regex on location ~ \.php$
block wrong. fastcgi_split_path_info
, fastcgi_index
directives unnecessary.
the nginx
directives documented here.