[LNMP] 사용자 인증 과 도 메 인 이름 변경

2694 단어 nginxCentOS7
사용자 인증
1. 가상 호스트 만 들 기
[root@juispan vhost]# vi /usr/local/nginx/conf/vhost/test.com.conf
server
{
    listen 80;
    server_name test.com;
    index index.html index.htm index.php;
    root /data/wwwroot/test.com;
    
location  /            ##             
    {
        auth_basic              "Auth";
        auth_basic_user_file   /usr/local/nginx/conf/htpasswd;
    }
}

2. 사용자 생 성
[root@juispan vhost]# yum install -y httpd
[root@juispan vhost]# htpasswd -c /usr/local/nginx/conf/htpasswd juispan
New password: 
Re-type new password: 
Adding password for user juispan

3. 검사 와 시작
[root@juispan vhost]# /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@juispan vhost]# /usr/local/nginx/sbin/nginx -s reload

4. 테스트 효과
[root@juispan vhost]# mkdir /data/wwwroot/test.com
[root@juispan vhost]# echo “test.com”>/data/wwwroot/test.com/index.html
[root@juispan vhost]# curl -x127.0.0.1:80 test.com -I
HTTP/1.1 401 Unauthorized
Server: nginx/1.12.1
Date: Tue, 08 Aug 2017 14:32:30 GMT
Content-Type: text/html
Content-Length: 195
Connection: keep-alive
WWW-Authenticate: Basic realm="Auth"

[root@juispan vhost]#  curl -ujuispan:mypasswd.com -x127.0.0.1:80 test.com -I
HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Tue, 08 Aug 2017 14:33:17 GMT
Content-Type: text/html
Content-Length: 15
Last-Modified: Tue, 08 Aug 2017 14:32:28 GMT
Connection: keep-alive
ETag: "5989cb7c-f"
Accept-Ranges: bytes

도 메 인 이름 변경
1. 가상 호스트 편집
[root@juispan vhost]# vi /usr/local/nginx/conf/vhost/test.com.conf
server
{
    listen 80;
    server_name test.com test1.com test2.com;  ##        
    index index.html index.htm index.php;
    root /data/wwwroot/test.com;
    if ($host != 'test.com' ) {
        rewrite  ^/(.*)$  http://test.com/$1  permanent;  ##     
    }
}

2. 검사 및 시작
[root@juispan vhost]# /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@juispan vhost]# /usr/local/nginx/sbin/nginx -s reload

3. 테스트 효과
[root@juispan vhost]# curl -x127.0.0.1:80 test1.com/abc.txt -I
HTTP/1.1 301 Moved Permanently   ##permanent 301,redirect 302
Server: nginx/1.12.1
Date: Tue, 08 Aug 2017 14:41:58 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: http://test.com/abc.txt

좋은 웹페이지 즐겨찾기