dou5454954610 2019-03-14 15:41
浏览 161

Nginx conf用于部署Yii2高级模板

I am new using Nginx and a have an advanced app developed using Yii2. I was working with apache server and I had this configuration for my 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 

But the hosting server at work has no apache server included, they only have Nginx, so I have built an Nginx configuration but, I can only see the frontend app. When I access /admin it runs the index.php file and redirects to login page but 404 not found is my server response. This is my 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;
    }  }

All resources news posters, games posters or files to download are available on backend/web/uploads folder, and it is well served. My problem is with backend and api app.

I tried recommended posts like Yii2 nginx conf and mickgeek/yii2-advanced-one-domain-config and others but they are not working for me.

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler
    • ¥15 oracle集群安装出bug
    • ¥15 关于#python#的问题:自动化测试