环境nginx+lnmp 新建typecho!
建网站的时候就开启了 www转非www的301转向
当安装好typecho后 进行测试发现
带www的域名打开后转向到非www域名,但是xxx.com//index.php
求解,静态规则什么的检测没问题! 郁闷
301转向问题
- m4go
- 帖子: 857
- 注册时间: 2010年 3月 29日 02:33
- 来自: https://www.vpshu.com
- 联系:
Re: 301转向问题
直接加伪静态,判断当前host,然后301转向。
代码: 全选
if ($host != 'vpsmm.com' ) {rewrite ^/(.*)$ http://www.vpsmm.com/$1 permanent;}
Re: 301转向问题
m4go 写了:直接加伪静态,判断当前host,然后301转向。代码: 全选
if ($host != 'vpsmm.com' ) {rewrite ^/(.*)$ http://www.vpsmm.com/$1 permanent;}
谢谢回答,我这里301代码配置是正确的,但就是不知道为什么转向出来的是//index,php
Re: 301转向问题
58458314 写了:比较郁闷的就是多了个/ 导致出现错误页面
贴出完整配置啊,不然没法帮你~
Re: 301转向问题
DT27 写了:贴出站点的完整nginx配置
静态规则
代码: 全选
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-e $request_filename){
rewrite (.*) /index.php;
}
网站的conf
代码: 全选
server {
listen 80;
listen 443 ssl http2;
ssl_certificate /usr/local/nginx/conf/ssl/xxx.com.crt;
ssl_certificate_key /usr/local/nginx/conf/ssl/xxx.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_timeout 10m;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_buffer_size 1400;
add_header Strict-Transport-Security max-age=15768000;
ssl_stapling on;
ssl_stapling_verify on;
server_name xxx.com www.xxx.com;
access_log /data/wwwlogs/xxx.com_nginx.log combined;
index index.html index.htm index.php;
include /usr/local/nginx/conf/rewrite/typecho.conf;
root /data/wwwroot/xxx.com;
if ($ssl_protocol = "") { return 301 https://$host$request_uri; }
if ($host != xxx.com) {
rewrite ^/(.*)$ $scheme://xxx.com/$1 permanent;
}
location ~ .*\.(wma|wmv|asf|mp3|mmf|zip|rar|jpg|gif|png|swf|flv)$ {
valid_referers none blocked *.xxx.com xxx.com xxx.com;
if ($invalid_referer) {
#rewrite ^/ http://xxx.com/403.htmll;
return 403;
}
}
location ~ [^/]\.php(/|$) {
#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
}
nginx配置
代码: 全选
user www www;
worker_processes auto;
error_log /data/wwwlogs/error_nginx.log crit;
pid /var/run/nginx.pid;
worker_rlimit_nofile 51200;
events {
use epoll;
worker_connections 51200;
multi_accept on;
}
http {
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 1024m;
client_body_buffer_size 10m;
sendfile on;
tcp_nopush on;
keepalive_timeout 120;
server_tokens off;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
#Gzip Compression
gzip on;
gzip_buffers 16 8k;
gzip_comp_level 6;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_proxied any;
gzip_vary on;
gzip_types
text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
text/javascript application/javascript application/x-javascript
text/x-json application/json application/x-web-app-manifest+json
text/css text/plain text/x-component
font/opentype application/x-font-ttf application/vnd.ms-fontobject
image/x-icon;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
#If you have a lot of static files to serve through Nginx then caching of the files' metadata (not the actual files' contents) can save some latency.
open_file_cache max=1000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
######################## default ############################
server {
listen 80;
server_name _;
access_log /data/wwwlogs/access_nginx.log combined;
root /data/wwwroot/default;
index index.html index.htm index.php;
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
location ~ [^/]\.php(/|$) {
#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
}
########################## vhost #############################
include vhost/*.conf;
}
上次由 58458314 在 2016年 8月 22日 15:29,总共编辑 1 次。
Re: 301转向问题
DT27 写了:58458314 写了:比较郁闷的就是多了个/ 导致出现错误页面
贴出完整配置啊,不然没法帮你~
在贴了朋友
Re: 301转向问题
58458314 写了:DT27 写了:58458314 写了:比较郁闷的就是多了个/ 导致出现错误页面
贴出完整配置啊,不然没法帮你~
在贴了朋友
网站的 conf 里,
代码: 全选
include /usr/local/nginx/conf/rewrite/typecho.conf;
root /data/wwwroot/xxx.com;
if ($ssl_protocol = "") { return 301 https://$host$request_uri; }
if ($host != xxx.com) {
rewrite ^/(.*)$ $scheme://xxx.com/$1 permanent;
}
改成
代码: 全选
root /data/wwwroot/xxx.com;
if ($ssl_protocol = "") { return 301 https://$host$request_uri; }
if ($host != xxx.com) {
rewrite ^/(.*)$ $scheme://xxx.com/$1 permanent;
}
include /usr/local/nginx/conf/rewrite/typecho.conf;
试试,改完后最好换个浏览器试试,301也有缓存。
Re: 301转向问题
已经搞定了朋友,是我缓存的问题,具体是哪个还不清楚。。反正我跑邻居家就可以正常转向。。。。