dongniaoli1822 2015-10-05 09:20
浏览 93

开发环境的Nginx站点配置

I'm currently trying to setup a generic, multi-project development environment in Vagrant for students of a web-development mentoring project. The idea is the domain <project>.vagrant maps to ~/code/<project> I thought I had enough experience with Nginx to solve this, but it turns out I don't.

Assuming that PHP-FPM is correctly setup, I need help with the try_files/routing for the site-configuration. Whilst the homepage (/) works fine, any request to a non-static file (which should therefore be passed to PHP-FPM) results in either a 301 Moved Permanently to the homepage, or downloads the contents of the PHP script instead of executing it.

And yes I know listing so many index files is not ideal but the students will be dealing with multiple projects (phpMyAdmin, WordPress) and frameworks (Symfony, Silex, Laravel, etc).

Any help with this would be greatly appreciated!

The contents of the single site-available configuration file so far is:

map $host $projectname {
    ~^(?P<project>.+)\.vagrant$ $project;
}

upstream phpfpm {
    server unix:/var/run/php5-fpm.sock;
}

server {
    listen 80;
    server_name *.vagrant;
    server_tokens off;
    root /home/vagrant/code/$projectname/web;
    index app_dev.php app.php index.php index.html;
    autoindex on;
    client_max_body_size 5M;
    location / {
        try_files $uri $uri/ / =404;
    }
    # Pass all PHP files onto PHP's Fast Process Manager server.
    location ~ [^/]\.php(/|\?|$) {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) {
            return 404;
        }
        try_files $fastcgi_script_name =404;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        # Specify the determined server-name, not the literal "*.vagrant".
        fastcgi_param SERVER_NAME $projectname.vagrant;
        fastcgi_pass phpfpm;
    }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 Revit2020下载问题
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
    • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数