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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能