LNMP搭建7:Nginx域名跳转
2017-02-25 12:44
211 查看
编辑Nginx的虚拟主机配置文件
[root@cp1 vhosts]# vim test.conf
将替他域名永久跳转到主域名301
server
{
listen 80;
server_name www.test.com www.aaa.com www.bbb.com;
if($host != 'www.test.com')
{
rewrite ^/(.*)$ http://www.test.com/$1 permanent;
}
index index.html index.htm index.php;
root /data/www;
location ~ .*admin\.php$ {
auth_basic "aminglinux auth";
auth_basic_user_file /usr/local/nginx/conf/.htpasswd;
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
location /abc/ {
auth_basic "aminglinux auth";
auth_basic_user_file /usr/local/nginx/conf/.htpasswd;
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
}
测试配置无误后重新加载配置文件:
[root@cp1 vhosts]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@cp1 vhosts]# /etc/init.d/nginx reload
重新载入 Nginx: [确定]
测试:
[root@cp1 vhosts]# curl -x127.0.0.1:80 www.aaa.com -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.6.2
Date: Wed, 22 Feb 2017 17:01:46 GMT
Content-Type: text/html
Content-Length: 184
Connection: keep-alive
Location: http://www.test.com/ [root@cp1 vhosts]# curl -x127.0.0.1:80 www.bbb.com -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.6.2
Date: Wed, 22 Feb 2017 17:02:11 GMT
Content-Type: text/html
Content-Length: 184
Connection: keep-alive
Location: http://www.test.com/ 常见nginx的301和302配置参考帖子:http://ask.apelearn.com/question/4840
[root@cp1 vhosts]# vim test.conf
将替他域名永久跳转到主域名301
server
{
listen 80;
server_name www.test.com www.aaa.com www.bbb.com;
if($host != 'www.test.com')
{
rewrite ^/(.*)$ http://www.test.com/$1 permanent;
}
index index.html index.htm index.php;
root /data/www;
location ~ .*admin\.php$ {
auth_basic "aminglinux auth";
auth_basic_user_file /usr/local/nginx/conf/.htpasswd;
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
location /abc/ {
auth_basic "aminglinux auth";
auth_basic_user_file /usr/local/nginx/conf/.htpasswd;
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
}
测试配置无误后重新加载配置文件:
[root@cp1 vhosts]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@cp1 vhosts]# /etc/init.d/nginx reload
重新载入 Nginx: [确定]
测试:
[root@cp1 vhosts]# curl -x127.0.0.1:80 www.aaa.com -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.6.2
Date: Wed, 22 Feb 2017 17:01:46 GMT
Content-Type: text/html
Content-Length: 184
Connection: keep-alive
Location: http://www.test.com/ [root@cp1 vhosts]# curl -x127.0.0.1:80 www.bbb.com -I
HTTP/1.1 301 Moved Permanently
Server: nginx/1.6.2
Date: Wed, 22 Feb 2017 17:02:11 GMT
Content-Type: text/html
Content-Length: 184
Connection: keep-alive
Location: http://www.test.com/ 常见nginx的301和302配置参考帖子:http://ask.apelearn.com/question/4840
相关文章推荐
- LNMP环境搭建:Nginx安装、测试与域名配置
- LNMP—Nginx的域名跳转
- LNMP环境搭建:Nginx安装、测试与域名配置
- nginx 域名跳转 Nginx跳转自动到带www域名规则配置、nginx多域名向主域名跳转
- CentOS 5.5安装Nginx、PHP(FastCGI)、MySQL --搭建LNMP环境安装Wordpress
- CentOS5.5安装Nginx、PHP(FastCGI)、MySQL --搭建LNMP环境安装wordpress
- nginx 域名跳转.
- nginx 域名跳转一例~~~(rewrite、proxy)
- Debian+Nginx+PHP(FastCGI)+MySQL搭建LNMP服务器(三版)
- 搭建lnmp=(nginx+mysql+php)
- CentOS 5.5安装Nginx、PHP(FastCGI)、MySQL --搭建LNMP环境安装Wordpress、Discuz
- Ubuntu 搭建LNMP环境图文教程 配置nginx支持PHP
- 使用nginx进行裸域名的跳转
- nginx+mysql+php lnmp环境搭建
- Nginx之rewrite:域名与二级目录之间的跳转
- 高性能LNMP搭建(linux/nginx/mysql/php-fastcgi)
- 基于Nginx0.8.54+PHP5.3.4+MySQL5.5.8的全新LNMP稳定版架构搭建的VPS
- Nginx对于cname的域名跳转,虚拟机的调整
- nginx 域名跳转 Nginx跳转自动到带www域名规则配置、nginx多域名向主域名跳转
- Ubuntu 搭建LNMP环境图文教程 安装Nginx服务器