Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

(시리즈 글이 3개 있습니다.)
개발 환경 구성: 118. IIS Express - localhost 이외의 호스트 이름으로 접근하는 방법
; https://www.sysnet.pe.kr/2/0/1030

개발 환경 구성: 684. IIS Express로 호스팅하는 웹을 WSL 환경에서 접근하는 방법
; https://www.sysnet.pe.kr/2/0/13389

개발 환경 구성: 685. 로컬에서 개발 중인 ASP.NET Core/5+ 웹 사이트에 대해 localhost 이외의 호스트 이름으로 접근하는 방법
; https://www.sysnet.pe.kr/2/0/13395




IIS Express로 호스팅하는 웹을 WSL 환경에서 접근하는 방법

이번 글은 2가지 글의 내용이 콜라보를 이뤄 발생하는 현상을 설명합니다. ^^

IIS Express - localhost 이외의 호스트 이름으로 접근하는 방법
; https://www.sysnet.pe.kr/2/0/1030

WSL 2의 네트워크 통신 방법
; https://www.sysnet.pe.kr/2/0/12347




무심코, Windows 호스트 측에서 Visual Studio를 이용해 간단한 웹 사이트를 만들고 F5 디버깅을 실행해 iisexpress로 띄워둔 경우,

C:\temp> netstat -ano | findstr 28660
  TCP    0.0.0.0:28660          0.0.0.0:0              LISTENING       4
  TCP    [::]:28660             [::]:0                 LISTENING       4

이것을 WSL 측에 만들어 둔 python 스크립트를 이용해 다음과 같이 URL을 접근하려고 시도할 수 있을 것입니다. ^^

$ cat test.py
import requests
requests.get("http://localhost:28660/default.aspx")

$ python test.py
...[예외 발생]...

하지만 requests.get 호출에서 이런 오류를 보게 되는데요,

HTTPConnectionPool(host='localhost', port=28660): Max retries exceeded with url: /default.aspx (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f2bc6a665b0>: Failed to establish a new connection: [Errno 111] Connection refused'))


실제로 telnet이나 curl로 간단하게 테스트해도 마찬가지의 결과가 나옵니다.

$ telnet localhost 28660
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused

$ curl http://localhost:28660
curl: (7) Failed to connect to localhost port 28660: Connection refused

왜냐하면 WSL 측의 localhost/127.0.0.1은 가상 스위치로 분리돼 운영하므로 명시적인 호스트 측의 IP를 지정해야 되고, 이어서 iisexpress는 localhost 이외의 바인딩을 하지 않기 때문입니다.

따라서, 위의 문제를 해결하려면 iisexpress 측에서 localhost를 넘어서는 바인딩도 허용하도록 바꿔주어야 하고,

// 관리자 권한으로 실행

// 추가 방법
c:\Windows\System32> netsh http add urlacl url=http://*:28660/ user="testusr32"

// 삭제 방법
c:\Windows\System32> netsh http delete urlacl ur=http://*:28660/

iisexpress 측의 applicationhost.config에도 ":28660:localhost" 바인딩이 아닌 ":28660:" 바인딩으로 변경해야 합니다.

<sites>
    <site name="Development Web Site" id="1" serverAutoStart="true">
        <application path="/">
            <virtualDirectory path="/" physicalPath="c:\temp\web" />
        </application>
        <bindings>
            <binding protocol="http" bindingInformation=":28660:" /> <== 원래는 ":28660:localhost"
        </bindings>
    </site>
    ...[생략]...
</sites>




위와 같이 했는데도, 여전히 연결이 안 될 수 있습니다. 왜냐하면, 방화벽이 있는 경우 그럴 수 있는데요, 이에 대해서는 다음의 글을 보시고,

Windows에서 실행 중인 소켓 서버를 다른 PC 또는 WSL에서 접속할 수 없는 경우
; https://www.sysnet.pe.kr/2/0/13225

설정을 해주시면 됩니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 7/5/2023]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 106  107  108  109  110  111  112  113  114  115  116  [117]  118  119  120  ...
NoWriterDateCnt.TitleFile(s)
11034정성태8/25/201625588개발 환경 구성: 296. .NET Core 프로젝트를 NuGet Gallery에 배포하는 방법 [2]
11033정성태8/24/201623513오류 유형: 353. coreclr 빌드 시 error C3249: illegal statement or sub-expression for 'constexpr' function
11032정성태8/23/201622702개발 환경 구성: 295. 최신의 Visual C++ 컴파일러 도구를 사용하는 방법 [1]
11031정성태8/23/201618777오류 유형: 352. Error encountered while pushing to the remote repository: Response status code does not indicate success: 403 (Forbidden).
11030정성태8/23/201621951VS.NET IDE: 111. Team Explorer - 추가한 Git Remote 저장소가 Branch에 보이지 않는 경우
11029정성태8/18/201629241.NET Framework: 602. Process.Start의 cmd.exe에서 stdin만 redirect 하는 방법 [1]파일 다운로드1
11028정성태8/15/201622274오류 유형: 351. Octave 설치 시 JRE 경로 문제
11027정성태8/15/201624013.NET Framework: 601. ElementHost 컨트롤의 메모리 누수 현상
11026정성태8/13/201625149Math: 19. 행렬 연산으로 본 해밍코드
11025정성태8/12/201623970개발 환경 구성: 294. .NET Core 프로젝트에서 "Copy to Output Directory" 처리 [1]
11024정성태8/12/201623177오류 유형: 350. "nProtect GameMon" 실행 중에는 Visual Studio 디버깅이 안됩니다! [1]
11023정성태8/10/201624710개발 환경 구성: 293. Azure 구독 후 PaaS 서비스 만들어 보기
11022정성태8/10/201625233개발 환경 구성: 292. Azure Cloud Service 배포시 사용자 정의 작업을 추가하는 방법
11021정성태8/10/201622103오류 유형: 349. System.Runtime.Remoting.RemotingException - Type '..., ..., Version=..., Culture=neutral, PublicKeyToken=null' is not registered for activation [2]
11020정성태8/10/201625148VC++: 98. 원본과 대상 버퍼가 같은 경우 memcpy, wmemcpy 주의점
11019정성태8/10/201641983기타: 60. 도서: 시작하세요! C# 6.0 프로그래밍: 기본 문법부터 실전 예제까지 (2쇄 정오표)
11018정성태8/9/201626156.NET Framework: 600. 단일 메서드 내에서의 할당으로 알아보는 자바와 닷넷의 GC 차이점 [1]
11017정성태8/9/201627450웹: 33. HTTP 쿠키에 한글 값을 설정하는 방법
11016정성태8/7/201625461개발 환경 구성: 291. Windows Server Containers 소개
11015정성태8/7/201623773오류 유형: 348. Windows Server 2016 TP5에서 Windows Containers의 docker run 실행 시 encountered an error during Start failed in Win32
11014정성태8/6/201624531오류 유형: 347. Hyper-V Virtual Machine Management service Account does not have permission to open attachment
11013정성태8/6/201635315개발 환경 구성: 290. Windows 10에서 경험해 보는 Windows Containers와 docker [4]
11012정성태8/6/201625365오류 유형: 346. Windows 10에서 Windows Containers의 docker run 실행 시 encountered an error during CreateContainer failed in Win32 발생
11011정성태8/6/201626850기타: 59. outlook.live.com 메일 서비스의 아웃룩 POP3 설정하는 방법
11010정성태8/6/201623923기타: 58. Outlook에 설정한 SMTP/POP3(예:천리안 메일) 계정 암호를 잊어버린 경우
11009정성태8/3/201629093개발 환경 구성: 289. 2016-08-02부터 시작된 윈도우 10 1주년 업데이트에서 Bash Shell 사용 [8]
... 106  107  108  109  110  111  112  113  114  115  116  [117]  118  119  120  ...