我有一个网站 A,它运行良好。当访问网站 A/backend 时,nginx 内会使用子位置来为另一个网站提供服务。
使用我的配置,当转到 websiteA/backend 时会返回一个空白页,并且 js 和 css 会作为 html 返回。
你能帮助我吗?谢谢。
我的虚拟主机:
### Use to not log the route53 health checks in the logs
map $http_user_agent $log_ua {
"ELB-HealthChecker/2.0" 0;
default 1;
}
server {
server_name websiteA www.websiteA;
root /var/www/websiteA/;
index index.php index.html;
access_log /var/log/nginx/websiteA.access.log combined if=$log_ua;
error_log /var/log/nginx/websiteA.com.error.log;
# Return a 404 not found for every hidden files
location ~ /\. {
deny all;
return 404;
}
# set expiration of assets to MAX for caching
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
log_not_found off;
}
location / {
# Check if a file or directory index file exists, else route it to index.php.
try_files $uri /index.html;
}
location ~ ^/backend/ {
alias /var/www/backend/;
try_files $uri $uri/ /index.php?$args;
location ~* \.php$ {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
fastcgi_param CI_ENV test;
fastcgi_param DOMAIN test;
include fastcgi.conf;
}
}
location ~ /(_sql|_templates|application|changelogs|docs|uploads|CHANGELOG.md|CSVTranslator.js|JSONUpdater.js|README.md|bower.json|composer.json|composer.lock|g_i18n_extractor.js|gulpfile.js|package-lock.json|package.json|robots.txt)
{
deny all;
return 404;
}
}
感谢您的帮助。