LNMP下的Nginx如果想将域名lnmp.org 301重定向到www.baidu.com
在我们VPS中的/usr/local/nginx/conf/vhost/域名.conf,我们会看到自己网站的域名命名的CONF文件,然后可以VI命令修改,也可以用FTP下载到本地修改再传上去;
server
{
listen 80;
#listen [::]:80;
server_name Lnmp.org ;
return 301 https://www.baidu.com; //复制整段地址并更改地址
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/lnmp;
include rewrite/none.conf;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include enable-php.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log off;
}
参考资料:
#Lnmp
https://lnmp.org/faq/lnmp-nginx-301-rewrite.html
#老左笔记
https://www.laozuo.org/206.html
编辑完成记得重启Nginx
#命令
/etc/init.d/nginx restart
Nginx 利用return实现301跳转
第一种
server
{
location / {
rewrite ^/(.*)$ http://www.baidu.com/$1 permanent;
}
}
第二种
server
{
location / {
return 301 http://www.baidu.com;
}
}
第三种
server
{
location / {
#default_type 指定显示格式,不可缺少,!-f /home/999 主要用于使条件为真,因为/home下并没有文件夹999
default_type text/html;
if (!-f /home/999) {
return 200 "<html><script>window.location.href='http://www.baidu.com'</script></html>";
}
}
}
作者:Alone°李道长ご