主静态网站(镜像)位于:/home/mirrors/mirror
我只在子目录/home/mirrors/mirror/phpweb/
中尝试设置PHP网站。到目前为止,它加载PHP,但所有图像,css和url链接指向/home/mirrors/mirror/filename*
而不是/home/mirrors/mirror/phpweb/filename*
我试过了:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
但是这导致错误日志显示:
在stderr中发送的FastCGI:"无法打开主脚本: /home/mirrors/mirror/phpweb/phpweb/index.php
最接近工作配置的是使用以下方法设置路径的错误方法:
fastcgi_param SCRIPT_FILENAME /home/mirrors/mirror$fastcgi_script_name;
我在俯瞰什么?这是整个配置。基本上它的工作原理除了images / css / js没有指向phpweb /目录。我的配置似乎缺少一些可以在root / home / mirrors / mirror / phpweb中使用静态的行;指向该文件夹。
server {
listen 80;
listen 443 ssl http2;
server_name mirrors.domain.com;
if ($scheme = http) {
return 301 https://$http_host$request_uri;
}
location / {
root /home/mirrors/mirror;
index index.html index.htm;
include /home/mirrors/Nginx-Fancyindex-Theme/fancyindex.conf;
}
location /phpweb {
root /home/mirrors/mirror/phpweb;
index /phpweb/index.php;
}
location ~ /phpweb/.*\.php$ {
root /home/mirrors/mirror/phpweb;
# try_files $uri =404;
# try_files $uri $uri/ =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/mirrors/mirror$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
Here's where I found a config example.
更新:此处更新了配置:
server {
listen 80;
listen 443 ssl http2;
server_name mirrors.domain.com;
root /home/mirrors/mirror;
if ($scheme = http) {
return 301 https://$http_host$request_uri;
}
location / {
index index.html index.htm;
include /home/mirrors/Nginx-Fancyindex-Theme/fancyindex.conf;
}
location /phpweb {
index /phpweb/index.php;
}
location ~ /phpweb/.*\.php$ {
try_files $uri =404;
# try_files $uri $uri/ =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# fastcgi_param SCRIPT_FILENAME /home/mirrors/mirror/phpweb$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
结果是:
警告:include(/home/mirrors/mirror/include/site.inc):失败 open stream:没有这样的文件或目录 第78行/home/mirrors/mirror/phpweb/include/prepend.inc
警告:include():打开失败 ' /home/mirrors/mirror/include/site.inc'包括在内 (include_path ='。:/ usr / share / php:/ usr / share / pear')in 第78行/home/mirrors/mirror/phpweb/include/prepend.inc
警告:include(/home/mirrors/mirror/include/langchooser.inc):失败 打开流:没有这样的文件或目录 第81行/home/mirrors/mirror/phpweb/include/prepend.inc
警告:include():打开失败 ' /home/mirrors/mirror/include/langchooser.inc'包括在内 (include_path ='。:/ usr / share / php:/ usr / share / pear')in 第81行/home/mirrors/mirror/phpweb/include/prepend.inc
警告:include(/home/mirrors/mirror/include/ip-to-country.inc): 无法打开流:没有这样的文件或目录 第84行/home/mirrors/mirror/phpweb/include/prepend.inc
警告:include():打开失败 ' /home/mirrors/mirror/include/ip-to-country.inc'包括在内 (include_path ='。:/ usr / share / php:/ usr / share / pear')in 第84行/home/mirrors/mirror/phpweb/include/prepend.inc
警告:include(/home/mirrors/mirror/include/layout.inc):失败 open stream:没有这样的文件或目录 第87行/home/mirrors/mirror/phpweb/include/prepend.inc
警告:include():打开失败 ' /home/mirrors/mirror/include/layout.inc'包括在内 (include_path ='。:/ usr / share / php:/ usr / share / pear')in 第87行/home/mirrors/mirror/phpweb/include/prepend.inc
警告:include(/home/mirrors/mirror/include/last_updated.inc): 无法打开流:没有这样的文件或目录 第92行/home/mirrors/mirror/phpweb/include/prepend.inc
警告:include():打开失败 ' /home/mirrors/mirror/include/last_updated.inc'包括在内 (include_path ='。:/ usr / share / php:/ usr / share / pear')in 第92行/home/mirrors/mirror/phpweb/include/prepend.inc
警告:include_once(/home/mirrors/mirror/include/releases.inc): 无法打开流:没有这样的文件或目录 第2行/home/mirrors/mirror/phpweb/include/branches.inc
警告:include_once():打开失败 ' /home/mirrors/mirror/include/releases.inc'包括在内 (include_path ='。:/ usr / share / php:/ usr / share / pear')in 第2行/home/mirrors/mirror/phpweb/include/branches.inc
警告:include_once(/home/mirrors/mirror/include/version.inc): 无法打开流:没有这样的文件或目录 第3行/home/mirrors/mirror/phpweb/include/branches.inc
警告:include_once():打开失败 ' /home/mirrors/mirror/include/version.inc'包括在内 (include_path ='。:/ usr / share / php:/ usr / share / pear')in 第3行/home/mirrors/mirror/phpweb/include/branches.inc
致命错误:调用未定义的函数mirror_setcookie() 第44行/home/mirrors/mirror/phpweb/index.php
以前(在这篇文章中粘贴的原始配置)我们没有php错误和页面加载。但是图像/静力学如上所述被打破了。
答案 0 :(得分:1)
root
指令指定物理路径的一部分,该部分以URI为前缀以查找物理文件。有关详细信息,请参阅this document。
因此,在您发布的配置中,我认为root
的值在所有三个位置都应该相同:
root /home/mirrors/mirror;
实际上,通常在root
块中指定server
指令一次,并允许将其继承到每个位置。例如:
root /home/mirrors/mirror;
location / { ... }
location /phpweb { ... }
location ~ \.php$ { ... }