模块化nginx配置不起作用

时间:2015-04-05 00:08:52

标签: laravel nginx hhvm

我在Unix套接字上使用Ubuntu 14.04 + nginx + HHVM 我有一些项目,都在不同子目录下的相同IP下运行。我一直在尝试使配置模块化,因此当项目发生变化时,只需要进行小的更改。但是,没有一个站点正在运行。我得到的是一个简单的404文件未找到'没有HTML标记的页面。 nginx和HHVM的错误日志都没有显示出来。

这是我的目录结构:

nginx/
  main/
    index.php
  phpmyadmin/
    index.php
  laravel/
    public/
      index.php

我的nginx配置:

全球

server {
  listen 80 default_server;
  listen [::]:80 default_server;

  server_name localhost;

  access_log    /var/log/nginx/access.log;
  error_log     /var/log/nginx/error.log info;
  charset utf-8;

  root /usr/share/nginx;

  include /etc/nginx/sites-available/main.conf;
  #include /etc/nginx/sites-available/phpmyadmin.conf;
  #include /etc/nginx/sites-available/laravel.conf;

  include hhvm.conf;

  # Deny .htaccess file access
  location ~ /\.ht {
      deny all;
  }
}

main.conf

location / {
  root /usr/share/nginx/main;
  index index.php;
  try_files $uri $uri/ =400;
}

hhvm.conf

location ~ \.(hh|php)$ {
    fastcgi_keep_conn on;
    # fastcgi_pass   127.0.0.1:9000;
    fastcgi_pass   unix:/var/run/hhvm/hhvm.sock;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

2 个答案:

答案 0 :(得分:0)

也许最简单的方法是为每个项目创建一个vhost。所以你有一个域(在网址中没有文件夹),它也是模块化的。

但是如果你想继续使用你的结构,可以使用这个配置:

# For example for your main:
location /main {
  root /usr/share/nginx/main;
  include hhvm.conf;
  index index.php;
  try_files $uri $uri/ =400;
}

/ main,/ phpmyadmin和/ laravel需要这些块。

但是,这个解决方案的问题可能是,例如laravel最容易在laravel.local这样的域上使用,而不是像pc.local/laravel这样的文件夹,因为你需要重写它所需的url。 这将是为每个文件夹切换到具有自己的域的vhosts的另一个原因。子域名也是可能的。

答案 1 :(得分:0)

这是我更新的配置文件,所以它可以工作(Laravel仍在进行中,只有主页工作,这很痛苦):

PKeidel的回答是被接受的,因为他激励我做出这个。谢谢!

server {
  listen 80 default_server;
  listen [::]:80 default_server;

  server_name localhost;

  access_log    /var/log/nginx/access.log;
  error_log     /var/log/nginx/error.log debug;
  charset utf-8;

  include sites-available/main.conf; 
  include sites-available/phpmyadmin.conf;
  include sites-available/laravel.conf;

  # Deny .htaccess file access
  location ~ /\.ht {
      deny all;
  }
}

main.conf

location ^~ / {
  root /usr/share/nginx/yoyo;
  include php-template;
  try_files $uri $uri/ =404;
}

phpmyadmin.conf

location ^~ /pma {
  root /usr/share/nginx;
  include php-template;
  try_files $uri $uri/ index.php?$query_string;
}

PHP-模板

index index.php;
include hhvm.conf;