
一下,一去!我完全理解之前配置中出現的所有問題,並再次感謝 Stack Overflow 上的 Cemal。 /location/ 現在顯示index.php。
新的問題是重寫規則。它們目前是全域設定的,每個位置都需要做同樣的事情(它們是重複的 PHP 前端,但對某些事情的存取權限有限。)
目前,主domain.com可以工作,但mydomain.com/test正在載入主PHP,但不傳遞重寫中的資料。我找到了一種讓它與嘗試文件一起工作的方法,但我很難使用正則表達式的建議讓它工作在這裡找到。
就目前情況而言,儘管這些文件存在,但以下內容會導致無法在 nginx 中找到 raw_data 或 generic_data 的錯誤,因此我只能假設它必須是重寫規則。
我複製了現有的重寫規則,並以 /test2/ 作為前綴,但仍然無法找到它們。
2018/02/27 13:37:46 [錯誤] 31485#31485: *49483 open()
"/var/www/html/test2/general_data" failed (2: No such file or
directory), client: X.X.X.X, server: mydomain.co.uk, request: "POST
/test/weather_data?cell HTTP/1.1", host: "mydomain.co.uk", referrer:
"https://mydomain.co.uk/test2/" 2018/02/27 13:37:46 [error]
31485#31485: *49546 open() "/var/www/html/test/raw_data" failed (2: No
such file or directory), client: X.X.X.X, server: my domain.co.uk,
request: "POST /test/raw_data HTTP/1.1", host: "mydomain.co.uk",
referrer: "https://mydomain.co.uk/test2/"
無論如何,這就是導致我得出結論的錯誤。
這是我目前的配置相關部分-
}server {
rewrite ^/raw_data$ /raw_data.php?$1 last;
rewrite ^/test_data$ /test_data.php?$1 last;
rewrite ^/motd_data$ /motd_data.php?$1 last;
rewrite ^/(.*)map.common.js$ /static/js/map.common.php last;
rewrite ^/general_data$ /general_data.php?$1 last;
rewrite ^test2/raw_data$ /test2/raw_data.php?$1 last;
rewrite ^test2/test_data$ /test2/test_data.php?$1 last;
rewrite ^test2/motd_data$ /test2/motd_data.php?$1 last;
rewrite ^test2/(.*)map.common.js$ /PMSFE/static/js/map.common.php last;
rewrite ^test2/general_data$ /PMSFE/general_data.php?$1 last;
location / {
include /etc/nginx/mime.types;
index index.php index.html index.htm;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param HTTP_IF_NONE_MATCH $http_if_none_match;
fastcgi_param HTTP_IF_MODIFIED_SINCE $http_if_modified_since;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
location /test2 {
include /etc/nginx/mime.types;
root /var/www/html/;
index index.php index.html index.htm;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param HTTP_IF_NONE_MATCH $http_if_none_match;
fastcgi_param HTTP_IF_MODIFIED_SINCE $http_if_modified_since;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
任何關於如何讓這個工作的建議都將非常感激,這是我第一次使用Linux,更不用說嘗試託管一些實質性的東西了,不幸的是,你發現的nginx 示例是如此不同,很難判斷什麼適用於你的特殊情況與否。
我嘗試在每個位置中包含重寫規則,就像我在另一篇文章中看到的那樣,但這破壞了mydomain.co.uk 頁面,並出現與新的mydomain.co.uk/test2/相同的錯誤
答案1
我太傻了。我的重寫一/短。
rewrite ^/test2/raw_data$ /test2/raw_data.php?$1 last;
rewrite ^/test2/test_data$ /test2/test_data.php?$1 last;
rewrite ^/test2/motd_data$ /test2/motd_data.php?$1 last;
rewrite ^/test2/(.*)map.common.js$ /PMSFE/static/js/map.common.php last;
rewrite ^/test2/general_data$ /PMSFE/general_data.php?$1 last;
現在可以了!