The Words are like Making Love.
VPS里用LNMP一键安装包装了个LNMP,想把没有www的主页转到加了www的主页
比如输入 vez.me 进入的就是www.vez.me。这样看起来比较顺眼。
找了一下Nginx的301方法。
首先vi /usr/local/nginx/conf/vhost/vez.me.conf (这个是我的配置文件,你的也是在这个文件夹下,但取决于你取的名字,如找不到可以先用以下办法找到)
cd /usr/local/nginx/conf/vhost/
dir
会列出所有的虚拟主机配置文件
我的虚拟主机配置文件如下。蓝色的部分就是要加上去设置301的代码。
方法1
server
{
listen 80;
server_name vez.me www.vez.me;
if ($host != 'www.vez.me' ) {
rewrite ^/(.*)$ https://www.vez.me/$1 permanent; }
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/vez.me;
include wordpress.conf;
location ~ .*\.(php|php5)?$
{
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
log_format vezblog '$remote_addr - $remote_user [$time_local] $request '
'$status $body_bytes_sent $http_referer '
'$http_user_agent $http_x_forwarded_for';
access_log /home/wwwlogs/vezblog.log vezblog;
}
方法2
(两种只用一种即可)
在配置文件最后面加上如下代码:
server { server_name lnmp.org; return 301 $scheme://www.lnmp.org$request_uri; }
然后执行
/etc/init.d/nginx restart 重启nginx,使其生效
然后测试一下301
[root@localhost vhost]# curl -I vez.me HTTP/1.1 301 Moved Permanently Server: nginx/1.0.10 Date: Sun, 18 Mar 2012 04:31:32 GMT Content-Type: text/html Content-Length: 185 Connection: keep-alive Location: https://www.vez.me /
博客速度挺快的
博主用的vps?哪的机房?
@狂奔的蜗牛 没用VPS了。放的是衡天的主机
蚊子终于更新了。 没想到蚊子也整代码。 表示看到鸭梨很大 :arrow:
@小托 @小托 哈哈。。多面手。瞎捣鼓。