全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 1019|回复: 11
打印 上一主题 下一主题

Nginx 1.8.0 301你们对吗?

[复制链接]
跳转到指定楼层
1#
发表于 2015-5-22 10:27:15 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
本帖最后由 __蛋丶碎 于 2015-5-22 11:28 编辑

server {
server_name www.sunk.eu.org sunk.eu.org;
rewrite ^(.*) http://sunk.eu.org$1 permanent;
}

就是报错 nginx: [emerg] unknown directive "server" in /usr/local/nginx/conf/hostloc.conf:1


经二楼
server {
server_name sunk.eu.org;
rewrite ^(.*) http://www.sunk.eu.org$1 permanent;
}

Stoping nginx... nginx: [emerg] "server" directive is not allowed here in /usr/local/nginx/conf/hostloc.conf:1
failed. Use force-quit
Starting nginx... nginx (pid 15692 15691 15690 15689 15688 15687 15686 15685 15684) already running.
12#
发表于 2015-5-22 17:30:13 | 只看该作者
__蛋丶碎 发表于 2015-5-22 16:44
server
        {
                listen 80;


第一个server_name中把主域名写上,不要写待转向的域名

然后原配置尾新开一个如下格式,把待转的域名写在server_name中,下面主域名
就是访问baidu.com会跳转到www.baidu.com去

  1. server {
  2.             listen       80;
  3.             server_name  baidu.com;
  4.             rewrite ^/(.*) http://www.baidu.com/$1 permanent;
  5. }
复制代码
11#
 楼主| 发表于 2015-5-22 16:44:16 | 只看该作者
junhan 发表于 2015-5-22 12:06
不知你怎么搞的,我使用LNMP,该域名全部配置如何下,你试试:

server
        {
                listen 80;
                #listen [::]:80;
                server_name www.baidu.com baidu.com img.baidu.com;
                index index.html index.htm index.php default.html default.htm default.php;
                root  /home/wwwroot/www.baidu.com;

                include baidu.conf;
                #error_page   404   /404.html;
                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 off;
        }
10#
发表于 2015-5-22 16:02:57 | 只看该作者
很明显,你需要贴全部配置。
9#
发表于 2015-5-22 15:44:36 | 只看该作者
你 server 的上层 directive 是什么?
8#
发表于 2015-5-22 15:40:01 | 只看该作者
__蛋丶碎 发表于 2015-5-22 11:19
server {
server_name sunk.eu.org;
rewrite ^(.*) http://bbs.cm8.org$1 permanent;

server中需要加上:listen 80;
7#
发表于 2015-5-22 12:06:02 | 只看该作者

不知你怎么搞的,我使用LNMP,该域名全部配置如何下,你试试:

  1. server
  2.         {
  3.                 listen 80;
  4.                 #listen [::]:80;
  5.                 server_name www.baidu.com;
  6.                 index index.html index.htm index.php default.html default.htm default.php;
  7.                 root  /home/wwwroot/www.baidu.com;

  8.                 include none.conf;
  9.                 #error_page   404   /404.html;
  10.                 location ~ [^/]\.php(/|$)
  11.                         {
  12.                                 # comment try_files $uri =404; to enable pathinfo
  13.                                 try_files $uri =404;
  14.                                 fastcgi_pass  unix:/tmp/php-cgi.sock;
  15.                                 fastcgi_index index.php;
  16.                                 include fastcgi.conf;
  17.                                 #include pathinfo.conf;
  18.                         }

  19.                 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  20.                         {
  21.                                 expires      30d;
  22.                         }

  23.                 location ~ .*\.(js|css)?$
  24.                         {
  25.                                 expires      12h;
  26.                         }

  27.                 access_log  /home/wwwlogs/www.baidu.com.log  access;
  28.         }
  29. server {
  30.             listen       80;
  31.             server_name  baidu.com;
  32.             rewrite ^/(.*) http://www.baidu.com/$1 permanent;
  33. }
复制代码
5#
 楼主| 发表于 2015-5-22 11:19:22 | 只看该作者
Fun 发表于 2015-5-22 10:31
sunk.eu.org不能在server_name里面

server {
server_name sunk.eu.org;
rewrite ^(.*) http://www.sunk.eu.org$1 permanent;
}

Stoping nginx... nginx: [emerg] "server" directive is not allowed here in /usr/local/nginx/conf/hostloc.conf:1
failed. Use force-quit
Starting nginx... nginx (pid 15692 15691 15690 15689 15688 15687 15686 15685 15684) already running.
4#
发表于 2015-5-22 10:50:05 | 只看该作者
见2楼的,,

需要转的和被转你都一样了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2025-11-11 20:32 , Processed in 0.093233 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表