2012-03-31 3 views
4

저는 www가 포함될 때 nginx를 사용하여 작동하도록 도메인을 얻는 데 문제가 있습니다. url에서.도메인에서 www가 nginx에서 작동하지 않습니다.

명명 된 구성 파일 또는 nginx에 대한 서버 구성을 실수로 잘못했는지 확실하지 않습니다. 나는 약간의 서두 르기를 배우고 있는데, 기본 구성에 약간의 오류가 있으면 놀라지 않을 것입니다. 나는 최신 nginx & php-fpm을 실행하는데, 이는 도메인 문제와 별개로 작동한다.

하위 도메인을 실행하려면 (노력하고 있습니까?) 작동하지만 www를 사용하고 있습니다. 404가됩니다. 내 메인 서버 .org 서버 도메인의 네임 서버 등을 사용합니다. 나는 아래의 관련성이있는 모든 것을 게시하여 누군가 내가 여기 만들고있는 오류를 발견 할 수 있기를 바랍니다.

etc/hosts 
# Do not remove the following line, or various programs 
# that require network functionality will fail. 
127.0.0.1  localhost.localdomain localhost 
::1    localhost6.localdomain6 localhost6 
184.xxx.xxx.146 server.servername.org servername.org 

named.conf의

... 
    view "localhost_resolver" { 
/* This view sets up named to be a localhost resolver (caching only nameserver). 
* If all you want is a caching-only nameserver, then you need only define this view: 
*/ 
    # match-clients   { 127.0.0.0/24; }; 
    # match-destinations { localhost; }; 
    match-clients  { any; }; 
    match-destinations { any; }; 
    recursion no; 

     zone "servername.org" { 
       type master; 
       file "/var/named/servername.org.db"; 
     }; 

// optional - we act as the slave (secondary) for the delegated domain 
zone "mydomain.com" IN { 
    type slave; 
    file "/var/named/mydomain.com.db"; 
    masters {10.10.0.24;}; 
}; 
allow-notify { 184.xxx.xxx.146; }; 
}; 

mydomain.com.db

$TTL 86400 
mydomain.com. IN  SOA  ns1.servername.org.  server.servername.org.  (
           2002012013; Serial 
           1H  ; Refresh (change 1H to 6H in 3 days or so) 
           1800 ; Retry (change to 1H in 3 days) 
           2W  ; Expire 
           1D); Minimum 
mydomain.com.   IN  NS  ns1.servername.org. 
mydomain.com.   IN  NS  ns2.servername.org. 
ns1.servername.org.    IN  A  184.xxx.xxx.147 
ns2.servername.org.    IN  A  184.xxx.xxx.148 
mail.servername.org.    IN  A  184.xxx.xxx.146 
mydomain.com.   IN  A  184.xxx.xxx.146 
mydomain.com.   IN  MX  0  mail.servername.org. 
@        A  184.xxx.xxx.146 
www       A  184.xxx.xxx.146 

nginx.conf가 사용하는 등의/etc/nginx를/사이트 사용/*; 나는 그래서이 나의 끔찍한 시도가 가지 일 것 같다, 하위 도메인에 액세스 할 수 있습니다

server { 
    server_name www.mydomain.com; 
    rewrite ^(.*) http://mydomain.com$1 permanent; 
} 
server { 
listen 80; 
server_name mydomain.com www.mydomain.com; 

    # access_log /srv/www/mydomain.com/logs/access.log; 
    error_log /srv/www/mydomain.com/logs/error.log; 
    root /srv/www/mydomain.com/public_html; 
    set $noadmin 1; 

    location/{ 
     try_files $uri $uri/ /index.php?$args; 
     index index.html index.htm index.php; 
    } 

    # Add trailing slash to */wp-admin requests. 
    rewrite /wp-admin$ $scheme://$host$uri/ permanent; 

    location ~ \.flv$ { 
      flv; 
      root /srv/www/mydomain.com/public_html; 
    } 

    location ~ \.mp4$ { 
      root /srv/www/mydomain.com/public_html; 
      mp4; 
    } 

    # use fastcgi for all php files 
     location ~ \.php$ { 
     try_files $uri =404; 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME /srv/www/mydomain.com/public_html$fastcgi_script_name; 
     include fastcgi_params; 
    } 

# deny access to apache .htaccess files 
    location ~ /\.ht 
    { 
     deny all; 
    } 
} 

의 nginx "mydomain.com"설정은, 내가있는 동안, www.mydomain.com가 연결되지 않는 이유에 붙어 있어요 http://mydomain.com됩니다. 나는 내가 따라갈 때 독서/학습을 더 많이하고 있으며, 나는 변화가 무엇을하는지 이해할 때까지 변화를 원하지 않는다. 결국 URL을 깨뜨릴 수 있습니다.

답변

5

nginx.conf의 처음 몇 줄에 www.domain.com을 다시 쓰고 있습니다. 내가 틀렸어도 재 작성 및 리디렉션은 다른 것입니다. 먼저 시도하십시오 서버 블록;

server { 
    server_name www.mydomain.com; 
    return  301 http://mydomain.com$request_uri; 
} 

server_name mydomain.com www.mydomain.com 

server_name mydomain.com 

번째 서버에 블록을 변경.

+0

고마워요 :) 두 번째 서버 블록에서 www를 제거하는 것은 저를 위해 트릭을 만들었습니다. 맨 위의 재 작성은 www를 사용하는 모든 사람이 수행합니다. http //로 보내지는데, 그게 더 효과적이라는 것을 알았지 만 지금도 작동 중입니다. 당신의 도움을 주셔서 감사합니다! http://wiki.nginx.org/Pitfalls#Taxing_Rewrites – DOA

+0

가끔씩 더 많은 server_name 지시어를 추가하려면'http {server_names_hash_bucket_size NN}'을 늘려야 할 수도 있습니다. 여기서 NN은 32보다 큰 수입니다. – nurettin

관련 문제