Tim*_*thy 12 php nginx fastcgi
我对我的 nginx 配置感到沮丧,所以我要求帮助编写我的配置文件,以从同一根目录的子目录中提供多个项目。这不是虚拟主机,因为它们都使用相同的主机值。也许一个例子可以澄清我的尝试:
192.168.1.1/
应当成为index.php
从/var/www/public/
192.168.1.1/wiki/
应当成为index.php
从/var/www/wiki/public/
192.168.1.1/blog/
应当成为index.php
从/var/www/blog/public/
这些项目使用 PHP 并使用 fastcgi。
我目前的配置非常小。
server {
listen 80 default;
server_name localhost;
access_log /var/log/nginx/localhost.access.log;
root /var/www;
index index.php index.html;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
include fastcgi_params;
}
}
Run Code Online (Sandbox Code Playgroud)
我已经试过各种事情alias
和rewrite
,但没能得到的东西正确的FastCGI的设置。这似乎应该有比写位置的块,复制更雄辩的方式root
,index
,SCRIPT_FILENAME
,等。
任何让我朝着正确方向前进的指针都表示赞赏。
Mar*_*ald 16
由于您的项目实际上不在同一个根目录中,因此您必须为此使用多个位置。
location /wiki {
root /var/www/wiki/public;
}
location ~ /wiki/.+\.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /var/www/wiki/public$fastcgi_script_name;
}
location /blog {
root /var/www/blog/public;
}
location ~ /blog/.+\.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /var/www/blog/public$fastcgi_script_name;
}
Run Code Online (Sandbox Code Playgroud)
此外,将 fastcgi_index 放在您的 fastcgi_params 文件中,并将其包含在服务器级别,这样您的 php 位置就会尽可能小。
按位置+别名解决:
location / {
root /var/www/public;
index index.php;
}
location /blog/ {
alias /var/www/blog/public/;
index index.php;
}
location /wiki/ {
alias /var/www/wiki/public/;
index index.php;
}
location ~ \.php$ {
#your fastcgi configuration here
}
归档时间: |
|
查看次数: |
57499 次 |
最近记录: |