因为前几天买了W2的VPS,因为还在找对方解决一些事情,就装了下LNMP环境什么都没放,今天闲来无事,暂时放一个美女图片在上面,放了之后发现,我通过./vhost.sh建立的空间域名设置www.01mm.net,当打开不带www的01mm.net的时候,竟然是LNMP主目录的页面。
怎么让01mm.net自动转向www.01mm.net呢?这就是301重定向的问题了。
首先打开/usr/local/nginx/conf/vhost/www.01mm.net.conf文件,原代码如下:
server { listen 80; server_name www.01mm.net; index index.html index.htm index.php default.html default.htm default.php; root /home/wwwroot/www.01mm.net;
include other.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; }
access_log off; }
我在这段代码最后加入如下代码:
server { server_name 01mm.net; rewrite ^(.*) http://www.01mm.net$1 permanent; }
大家注意,如果原代码server_name后面有2个地址,包括了不带www的地址,请先删除之!
另外,修改完成后,请重启LNMP。
/root/lnmp stop
/root/lnmp start
到这里,301重定向就完成了。现在不输入www的地址,也能自动转到www了。来个美女图片站的图吧:
欢迎在站内搜索:个人域名备案、icp备案号、查询ip地址、域名注册中心、阿里云服务器、国外服务器vps、韩国高防服务器 国外vps服务器租用、永久免费的云服务器、网站备案信息查询