yii2 模块中使用restful的pretty url带参数导致404 not found cannot resolve url

在模块中加了restful接口,不带参数是可以正常访问的

base_url/controller/action

带上参数不能正常访问

base_url/controller/action/15

如果不用pretty url是可以的

base_url/controller/action?id=15

按照官方文档配置无效http://www.yiichina.com/doc/guide/2.0/rest-versioning

最后发现,用另一种方式声明url rule可以了

     components' => [
        ...
        'urlManager' => [
            'enablePrettyUrl'     => true,
            'enableStrictParsing' => false,
            'showScriptName'      => false,
            'rules' => [
                [
                    'class' => 'yii\rest\UrlRule',
                    'controller' => [
                        'api/v1_0/user',
                    ],
                    'tokens'=>[
                        '{id}'    => '<id:\\d[\\d,]*>', //default
                    ],
                    'extraPatterns'=>[
                        'GET,HEAD {id}/projects'           => 'projects',
                    ]
                ],
            ],
            'rules'=>[
                '<module:\w+>/<controller:\w+>/<action:\w+>/<id:\d+>'=>'<module>/<controller>/<action>',
            ],
        ]
    ],

我觉得我要弃坑了~~~

使用nginx反向代理docker容器实现不同域名访问不同容器

环境:

ubuntu 16.04

docker 17.05

nginx 1.10.3 (ubuntu)

首先安装nginx

apt-get install -y nginx

启动docker容器并映射端口

docker run -d -p 8080:80 --name domain1 httpd
docker run -d -p 8081:80 --name domain2 httpd

添加反向代理配置/etc/nginx/conf.d/reverse-proxy.conf

server
{
    listen 80;
    server_name domain1.com;
    location / {
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:8080;
    }
    access_log /var/log/nginx/domain1.com_access.log;
}

server
{
    listen 80;
    server_name domain2.com;
    location / {
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:8081;
    }
    access_log /var/log/nginx/domain2_access.log;
}

启动nginx

/etc/init.d/nginx start

 

 

http重定向到https

server
{
    listen	80;
    server_name	domain.com;
    return 	301 https://$server_name$request_uri;
}

server
{
    listen 443;
    server_name domain.com;
    ssl on;
    ssl_certificate /home/ca/yun2.nopass.crt;
    ssl_certificate_key /home/ca/yun2.nopass.key;
    location / {
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:8080;
    }
    client_max_body_size 512M;
    access_log /var/log/nginx/yun2.ahuer.com_access.log;
}