nginx虚拟目录支持PHP,刚apache转nginx,这个虚拟目录就是没法执行php,怎么搞?...

只需微调nginx的初始配置就可以,至于你用的 alias ,我这里没有用到。建议你这样配置。关键配置都写了中文注释。

nginx.conf

……

server

{

# 本地默认

listen 127.0.0.1:80;

server_name _;

index index.html index.htm index.php;

root /home/wwwroot/default; # 路径设置到nginx服务跟目录

include enable-php.conf;

……

access_log /home/wwwlogs/access.log;

}

include vhost/*.conf; # 导入每个项目的独立配置

vhost/demo.conf

server

{

listen 80;

#listen [::]:80 default_server ipv6only=on;

server_name demo.vm.com; # 设置虚拟域名访问不同的项目

index index.php index.htm index.html;

root /home/wwwroot/default/demo/public; # 设置到项目的入口文件所在目录

#error_page 404 /404.html;

# Deny access to PHP files in specific directory

#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

# laravel 这里是每个框架的url解析规则,不同框架稍有不同

location / {

try_files $uri $uri/ /index.php?$query_string;

}

# include enable-php-pathinfo.conf;

# 设置 nginx 转发到 php-fpm 或者也可以配置到另一个文件里,然后通过 include 引入

location ~ [^/]\.php(/|$)

{

try_files $uri =404;

fastcgi_pass unix:/tmp/php-cgi.sock;

fastcgi_index index.php;

include fastcgi.conf;

}

location /nginx_status

{

stub_status on;

access_log off;

}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

{

expires 30d;

}

location ~ .*\.(js|css)?$

{

expires 12h;

}

location ~ /.well-known {

allow all;

}

location ~ /\.

{

allow all;

}

access_log /home/wwwlogs/access.log;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值