- 首先到官网Yii Advanced 模板的git地址下载web服务器需要的配置文件
- 修改域名和代码目录,以nginx为例,我的域名是xiaohuasheng.cc,本地代码放在,
C:\Users\xhs\blog
, 所以 nginx 配置修改后如下:server { charset utf-8; client_max_body_size 128M;
listen 80; ## listen for ipv4 #listen [::]:80 default_server ipv6only=on; ## listen for ipv6 server_name xiaohuasheng.cc; root C:/Users/xhs/blog/frontend/web/; index index.php; #access_log /path/to/yii-application/log/frontend-access.log; #error_log /path/to/yii-application/log/frontend-error.log; location / { # Redirect everything that isn't a real file to index.php try_files $uri $uri/ /index.php$is_args$args; } # uncomment to avoid processing of calls to non-existing static files by Yii #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ { # try_files $uri =404; #} #error_page 404 /404.html; # deny accessing php files for the /assets directory location ~ ^/assets/.*\.php$ { deny all; } location ~ \.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; #fastcgi_pass unix:/var/run/php5-fpm.sock; try_files $uri =404; } location ~* /\. { deny all; } } server { charset utf-8; client_max_body_size 128M; listen 80; ## listen for ipv4 #listen [::]:80 default_server ipv6only=on; ## listen for ipv6 server_name admin.xiaohuasheng.cc; root C:/Users/xhs/blog/backend/web/; index index.php; #access_log /path/to/yii-application/log/backend-access.log; #error_log /path/to/yii-application/log/backend-error.log; location / { # Redirect everything that isn't a real file to index.php try_files $uri $uri/ /index.php$is_args$args; } # uncomment to avoid processing of calls to non-existing static files by Yii #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ { # try_files $uri =404; #} #error_page 404 /404.html; # deny accessing php files for the /assets directory location ~ ^/assets/.*\.php$ { deny all; } location ~ \.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; #fastcgi_pass unix:/var/run/php5-fpm.sock; try_files $uri =404; } location ~* /\. { deny all; } } </pre> </li> <li>本地没问题了上传配置文件<code>xiaohuasheng.conf</code>到服务器nginx配置文件目录<code>/etc/nginx/conf.d</code></li> <li>对应修改一下配置文件的root目录,CentOS服务器上的配置如下: <pre> server { charset utf-8; client_max_body_size 128M; listen 80; ## listen for ipv4 #listen [::]:80 default_server ipv6only=on; ## listen for ipv6 server_name xiaohuasheng.cc; root /usr/share/nginx/html/blog/frontend/web/; index index.php; #access_log /path/to/yii-application/log/frontend-access.log; #error_log /path/to/yii-application/log/frontend-error.log; location / { # Redirect everything that isn't a real file to index.php try_files $uri $uri/ /index.php$is_args$args; } # uncomment to avoid processing of calls to non-existing static files by Yii #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ { # try_files $uri =404; #} #error_page 404 /404.html; # deny accessing php files for the /assets directory location ~ ^/assets/.*\.php$ { deny all; } location ~ \.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; #fastcgi_pass unix:/var/run/php5-fpm.sock; try_files $uri =404; } location ~* /\. { deny all; } } server { charset utf-8; client_max_body_size 128M; listen 80; ## listen for ipv4 #listen [::]:80 default_server ipv6only=on; ## listen for ipv6 server_name admin.xiaohuasheng.cc; root /usr/share/nginx/html/blog/backend/web/; index index.php; #access_log /path/to/yii-application/log/backend-access.log; #error_log /path/to/yii-application/log/backend-error.log; location / { # Redirect everything that isn't a real file to index.php try_files $uri $uri/ /index.php$is_args$args; } # uncomment to avoid processing of calls to non-existing static files by Yii #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ { # try_files $uri =404; #} #error_page 404 /404.html; # deny accessing php files for the /assets directory location ~ ^/assets/.*\.php$ { deny all; } location ~ \.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; #fastcgi_pass unix:/var/run/php5-fpm.sock; try_files $uri =404; } location ~* /\. { deny all; } } </pre> </li> <li>重启nginx <code>/etc/init.d/nginx restart</code>,或者<code>service nginx restart</code> </li> <li>把yii URL manager 的代码放进 common/config/main.php,供参考:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'suffix'=>'.html',
'rules' => [
'<controller:\w+>/<id:\d+>'=>'<controller>/detail',
'posts'=>'post/index',
],
], - 我的域名是租腾讯云的,为了能访问二级域名
admin.xiaohuasheng.cc
,在腾讯云的域名解析添加规则记录类型 主机记录 线路类型 记录值 MX优先级 TTL(秒) 最后操作时间 操作 A admin 默认 114.215.111.84 - 600 2017-10-07 16:52:17 修改暂停删除 </pre>