用于部署Yii2高级模板的Nginx conf

时间:2019-03-14 15:41:26

标签: php nginx yii2

我是使用Nginx的新手,并且有一个使用Yii2开发的高级应用程序。我正在使用apache服务器,并且对VirtualHost进行了以下配置:

<VirtualHost *:80>
   DocumentRoot "path/to/cosmox/frontend/web"
   ServerName cosmox.com
   ServerAlias www.cosmox.com
   Alias /admin path/to/cosmox/backend/web
   Alias /uploads path/to/cosmox/backend/web/uploads
   Alias /api path/to/cosmox/api/web

   ErrorLog "logs/cosmox-error.log"
   CustomLog "logs/cosmox-access.log" common

   Options +FollowSymLinks 

但是工作中的托管服务器不包含apache服务器,它们只有Nginx,因此我已经构建了Nginx配置,但是,我只能看到前端应用程序。当我访问/ admin时,它运行index.php文件并重定向到登录页面,但是404 not found是我的服务器响应。这是我的Nginx conf:

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

    index index.php;
    error_log /var/log/nginx/cosmox.errors.log;
    access_log /var/log/nginx/cosmox.access.log combined;

    server_name cosmox.com www.cosmox.com;

    #root /path/to/cosmox/backend/web;

    location / {
        root /path/to/cosmox/frontend/web;
        index index.php;
        try_files $uri /index.php$is_args$args;

        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }
    }

    location /admin {
        alias /path/to/cosmox/backend/web;

        index index.php;
        #try_files $uri /index.php$is_args$args;    //This entry break the backend redirect

        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;  //this entry such throw a "File not found" text
       }
    }

    location /api {
        alias /path/to/cosmox/api/web;

        index index.php;
        #try_files $uri /index.php$is_args$args;

        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
            fastcgi_param SCRIPT_FILENAME $request_filename;
        }
    }

    location /uploads {
        alias /path/to/cosmox/backend/web/uploads;
        try_files $uri $uri;
    }

    location = /favicon.ico {
         try_files /favicon.ico =204;
    }  }

所有资源新闻海报,游戏海报或要下载的文件都可以在backend / web / uploads文件夹中找到,并且提供了很好的服务。我的问题是后端和api应用。

我尝试了推荐的帖子,例如Yii2 nginx confmickgeek/yii2-advanced-one-domain-config等,但它们对我没有用。

0 个答案:

没有答案