Nginx和Apache配置301跳转
2016-04-24 12:23
567 查看
Nginx配置301跳转
1、找到/usr/local/nginx/conf/vhost/下面的.conf文件。2、参考如下代码,见301跳转设置处:
server { listen 80; #listen [::]:80; server_name www.ju.com ju.com *.ju.com; index index.php; root /data/wwwroot/ju_2_1; #include other.conf; #error_page 404 /404.html; location / { index index.php; if (!-e $request_filename) { rewrite ^/(.*)$ /index.php last; } #301 跳转设置 if ($host = 'ju.com') { rewrite ^/(.*) http://www.ju.com/$1 permanent; } } location ~ [^/]\.php(/|$) { # comment try_files $uri =404; to enable pathinfo try_files $uri =404; fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; #include pathinfo.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } access_log /home/wwwlogs/ju.log access; }
另外以上代码还开启了域名泛解析。
3、重启Nginx即可。
Apache配置301跳转
1、打开/etc/httpd/conf/http.conf文件,开启Apache重写功能:#LoadModule rewrite_module modules/mod_rewrite.so将这一行前的#号去掉。
2、在/etc/httpd/conf.d/目录下新建.conf文件,输入如下代码:
<VirtualHost *:80> DocumentRoot "/home/wwwroot/ju" ServerName www.ju.net ServerAlias *.ju.net <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_HOST} ^ju.net [NC] RewriteRule ^(.*) http://www.ju.net$1 [R=301,L] </IfModule> </VirtualHost>另外以上代码还开启了域名泛解析。
3、重启Apache。
相关文章推荐
- 使用Nginx配置资源虚拟路径
- [置顶] Rails环境搭建与部署(Nginx+Passenger)
- Ubuntu 14.04 配置 Nginx + uWSGI 托管 virtualenv 下 Flask 应用的一点注意事项
- CentOS 7.2 编译nginx 添加自启服务
- CentOS7.2 Keepalived + Nginx 实现高可用性
- centos6.5安装nginx+keepalived实现高可用负载均衡
- Linux下安装php环境并且配置Nginx支持php-fpm模块
- 在aws的ec2服务器上搭建nginx+php的环境
- Nginx压力测试工具之WebBench
- 使用awstats分析nginx日志
- 使用ab对nginx进行压力测试
- Linux CentOS 7 & Tengine(Nginx)安装与配置
- Nginx安装
- Nginx优化教程 实现突破十万并发
- nginx 配置文件分析以及配置负载均衡器
- Nginx的一些基本功能
- Nginx配置文件nginx.conf详解(总结)
- Nginx配置性能基本优化的方法
- Nginx ServerName 配置说明(转)
- centos6.5 nginx开机启动