[英]CakePHP Htaccess 2 Nginx rewrite
我們正在將CakePHP Framework安裝移動到正在運行Nginx的服務器上。 先前的服務器具有Apache。 CakePHP在子文件夾上有多個子安裝,所有子安裝都包含/ app / webroot /文件夾。 我們設法使index.php正常工作,但是/ app / webroot /下的所有其他文件(如javascript和CSS)都沒有鏈接到那里。
現在,我們嘗試使它在具有多個不同變體的nginx上運行。 問題是,該網站加載了PHP文件並清理了URL的工作。 不會加載位於/ app / webroot /下的CSS和JS文件。
我們正在嘗試將根目錄設置為subdomain.example.com,其中存在帶有header()函數的index.php以將用戶重定向到文件夾,其中存在CakePHP。 子文件夾下基本上有多個站點。 因此CakePHP網站是http://subdomain.example.com/subfolder
這是我們正在嘗試的nginx conf。 我一直在嘗試各種不同的選擇,但沒有效果。
server {
rewrite ^(.*) http://example.com$1 permanent;
}
server {
listen 80;
server_name example.com www.example.com subdomain.example.com;
access_log /home/example.com/logs/access.log;
error_log /home/example.com/logs/error.log error;
root /home/example.com/public_html/;
index index.php;
gzip_static on;
location /subfolder {
root /home/example.com/public_html/subfolder/;
index index.php;
rewrite ^/subfolder/(/.*)$ /app/webroot$1 break;
try_files $uri $uri/ /subfolder/app/webroot/index.php?$args;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
location ~ \.php$ {
try_comles $uri =404;
include fastcgi_params;
fastcgi_pass unix:/var/run/example.com-php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
app / webroot /將是您的服務器根目錄。 並為進程index.php文件提供單獨的位置。
例:
server {
listen 80;
server_name yourserver.com;
root /web/path/;
index index.php;
location / {
rewrite ^(/.*)$ /app/webroot$1 break;
try_files $uri $uri/ /app/webroot/index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.