gpt4 book ai didi

ssl - XAMPP 中跨 LAN 的本地主机自签名证书

转载 作者:太空宇宙 更新时间:2023-11-03 15:08:04 24 4
gpt4 key购买 nike

我有带 ssl 的本地主机,在我的本地电脑上工作正常,但 ssl 不能跨 LAN 工作。因为我使用的是自签名证书,所以我必须在每台要打开网站的 PC 上安装证书,但它只能在托管网站的 PC 上运行,而不能在 LAN 上的其他 PC 上运行。

我不想在线托管我的网站,因为我处于开发模式。

我的本地电脑:

主机文件:

127.0.0.1 gofashion_chat.test

httpd-xampp.conf

<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/gofashion"
ServerName gofashion_chat.test
ServerAlias *.gofashion_chat.test
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "C:/xampp/htdocs/gofashion"
ServerName gofashion_chat.test
ServerAlias *.gofashion_chat.test
SSLEngine on
SSLCertificateFile "C:/xampp/htdocs/gofashion/cert/gofashion_chat.test/server.crt"
SSLCertificateKeyFile "C:/xampp/htdocs/gofashion/cert/gofashion_chat.test/server.key"
</VirtualHost>

浏览器中的证书:

Certificate in browser

局域网电脑:

主机文件:

192.168.10.7 gofashion_chat.test

局域网PC浏览器中的证书:

Certificate in browser on LAN PC

在两台电脑上都安装了server.crt

如何解决跨 LAN 的 ssl 问题?

编辑:

这是我用来生成证书的bat文件

@echo off

set /p domain="Enter Domain without TLD (E.g 'facebook', 'google'): "
set /p com_tld="Enter Domain TLD (E.g 'com', 'test'): "

SET HOSTNAME=%domain%
SET DOT=%com_tld%
SET COUNTRY=US
SET STATE=KS
SET CITY=Olathe
SET ORGANIZATION=IT
SET ORGANIZATION_UNIT=IT Department
SET FULL_DOMAIN=%HOSTNAME%.%DOT%
SET EMAIL=webmaster@%FULL_DOMAIN%

SET OPENSSL_CONF=C:\xampp\apache\conf\openssl.cnf

if not exist .\%HOSTNAME%.%DOT% mkdir .\%FULL_DOMAIN%

(
echo [req]
echo default_bits = 2048
echo prompt = no
echo default_md = sha256
echo req_extensions = v3_req
echo x509_extensions = x509_ext
echo distinguished_name = dn
echo:
echo [dn]
echo C = %COUNTRY%
echo ST = %STATE%
echo L = %CITY%
echo O = %ORGANIZATION%
echo OU = %ORGANIZATION_UNIT%
echo emailAddress = %EMAIL%
echo CN = %FULL_DOMAIN%
echo:
echo [v3_req]
echo subjectAltName = @alt_names
echo subjectKeyIdentifier = hash
echo authorityKeyIdentifier = keyid:always, issuer:always
echo basicConstraints = critical, CA:TRUE, pathlen:1
echo keyUsage = critical, cRLSign, digitalSignature, keyCertSign
echo nsComment = "OpenSSL Generated Certificate"
echo:
echo [x509_ext]
echo subjectAltName = @alt_names
echo subjectKeyIdentifier = hash
echo authorityKeyIdentifier = keyid:always, issuer:always
echo basicConstraints = critical, CA:TRUE, pathlen:1
echo keyUsage = critical, cRLSign, digitalSignature, keyCertSign
echo nsComment = "OpenSSL Generated Certificate"
echo:
echo [alt_names]
echo DNS.1 = *.%FULL_DOMAIN%
echo DNS.2 = %FULL_DOMAIN%
)>%FULL_DOMAIN%\%HOSTNAME%.cnf

C:\xampp\apache\bin\openssl req -new -x509 -newkey rsa:2048 -sha256 -nodes -keyout %FULL_DOMAIN%\server.key -days 356 -out %FULL_DOMAIN%\server.crt -config %FULL_DOMAIN%\%HOSTNAME%.cnf

echo.
echo -----
echo The certificate was provided.
echo.
pause

这是我用来生成证书的另一个。

@echo off

set /p domain="Enter Domain without TLD (E.g 'facebook', 'google'): "
set /p com_tld="Enter Domain TLD (E.g 'com', 'test'): "

SET HOSTNAME=%domain%
SET DOT=%com_tld%
SET COUNTRY=US
SET STATE=KS
SET CITY=Olathe
SET ORGANIZATION=IT
SET ORGANIZATION_UNIT=IT Department
SET FULL_DOMAIN=%HOSTNAME%.%DOT%
SET EMAIL=webmaster@%FULL_DOMAIN%

SET OPENSSL_CONF=C:\xampp\apache\conf\openssl.cnf

if not exist .\%HOSTNAME%.%DOT% mkdir .\%FULL_DOMAIN%

(
echo [ req ]
echo default_bits = 2048
echo default_keyfile = server-key.pem
echo distinguished_name = subject
echo req_extensions = req_ext
echo x509_extensions = x509_ext
echo string_mask = utf8only
echo:
echo [ subject ]
echo countryName = Country Name ^(2 letter code^)
echo countryName_default = %COUNTRY%
echo stateOrProvinceName = State or Province Name ^(full name^)
echo stateOrProvinceName_default = %STATE%
echo localityName = Locality Name ^(eg, city^)
echo localityName_default = %CITY%
echo organizationName = Organization Name ^(eg, company^)
echo organizationName_default = %ORGANIZATION%
echo commonName = Common Name ^(e.g. server FQDN or YOUR name^)
echo commonName_default = %HOSTNAME%.%DOT%
echo emailAddress = Email Address
echo emailAddress_default = %EMAIL%
echo:
echo [ x509_ext ]
echo subjectKeyIdentifier = hash
echo authorityKeyIdentifier = keyid,issuer
echo basicConstraints = CA:FALSE
echo keyUsage = digitalSignature, keyEncipherment
echo subjectAltName = @alternate_names
echo nsComment = "OpenSSL Generated Certificate"
echo:
echo [ req_ext ]
echo subjectKeyIdentifier = hash
echo basicConstraints = CA:FALSE
echo keyUsage = digitalSignature, keyEncipherment
echo subjectAltName = @alternate_names
echo nsComment = "OpenSSL Generated Certificate"
echo:
echo [ alternate_names ]
echo:
echo DNS.1 = *.%HOSTNAME%.%DOT%
echo DNS.2 = %HOSTNAME%.%DOT%
)>%FULL_DOMAIN%\%HOSTNAME%.cnf

C:\xampp\apache\bin\openssl req -new -x509 -newkey rsa:2048 -sha256 -nodes -keyout %FULL_DOMAIN%\server.key -days 356 -out %FULL_DOMAIN%\server.crt -config %FULL_DOMAIN%\%HOSTNAME%.cnf

echo.
echo -----
echo The certificate was provided.
echo.
pause

最佳答案

这可能会晚一点,但值得一试^_^

不要使用 gofashion_chat.test 指定您的本地主机,只需使用 computername.domain。这将节省您编辑要访问网站的每台计算机的主机的时间。

在 apache 中创建一个文件夹。文件夹名称:crt

创建一个名为cert-template.conf 的文件并将其保存在crt 文件夹中。以下是 cert-template.conf 的命令。

[ req ]

default_bits = 2048
default_keyfile = server-key.pem
distinguished_name = subject
req_extensions = req_ext
x509_extensions = x509_ext
string_mask = utf8only

[ subject ]

countryName = Country Name (2 letter code)
countryName_default = TE

stateOrProvinceName = State or Province Name (full name)
stateOrProvinceName_default = TEST

localityName = Locality Name (eg, city)
localityName_default = TEST

organizationName = Organization Name (eg, company)
organizationName_default = TEST

commonName = Common Name (e.g. server FQDN or YOUR name)
commonName_default = computername.domain

emailAddress = Email Address
emailAddress_default = test@example.com

[ x509_ext ]

subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer

basicConstraints = CA:FALSE
keyUsage = digitalSignature, keyEncipherment
subjectAltName = @alternate_names
nsComment = "OpenSSL Generated Certificate"

[ req_ext ]

subjectKeyIdentifier = hash

basicConstraints = CA:FALSE
keyUsage = digitalSignature, keyEncipherment
subjectAltName = @alternate_names
nsComment = "OpenSSL Generated Certificate"

[ alternate_names ]

DNS.1 = computername.domain

同时创建此文件:make-cert.bat 并将其保存在 crt 文件夹中。下面是make-cert.bat的命令。

@echo off
set /p domain="Domain Name: "
set OPENSSL_CONF=../conf/openssl.cnf

REM
REM Read the "cert-template.conf" file and replace all {{DOMAIN}} placeholders by the entered domain.
REM Write the result into a new file called "cert.conf".
REM
REM @see https://stackoverflow.com/questions/5273937/how-to-replace-substrings-in-windows-batch-file#20227248
REM
setlocal enabledelayedexpansion
set INTEXTFILE=cert-template.conf
set OUTTEXTFILE=cert.conf
set SEARCHTEXT={{DOMAIN}}
set REPLACETEXT=%domain%

if exist %OUTTEXTFILE% del /F %OUTTEXTFILE%
for /f "tokens=1,* delims=¶" %%A in ( '"findstr /n ^^ %INTEXTFILE%"') do (
SET string=%%A
for /f "delims=: tokens=1,*" %%a in ("!string!") do set "string=%%b"
if "!string!" == "" (
echo.>>%OUTTEXTFILE%
) else (
SET modified=!string:%SEARCHTEXT%=%REPLACETEXT%!
echo !modified! >> %OUTTEXTFILE%
)
)


REM
REM Create the target directory.
REM
if not exist .\%domain% mkdir .\%domain%


REM
REM Create the certificate and key files.
REM
..\bin\openssl req -config %OUTTEXTFILE% -new -sha256 -newkey rsa:2048 -nodes -keyout %domain%\server.key -x509 -days 365 -out %domain%\server.crt


REM
REM Delete the written file "cert.conf" as this file would only be used to create the certificate.
REM
if exist %OUTTEXTFILE% del /F %OUTTEXTFILE%


echo.
echo -----
echo The certificate was provided.
echo.
pause

运行 make-cert.bat,命令提示符将显示并要求您提供域名。您的域名是您的计算机名.域。之后,您需要回答一些问题,最重要的问题是通用名称。公用名 = Computername.domain。

安装您在 crt/computername.domain/server.crt 中创建的证书。安装证书>本地计算机>将所有证书放入以下存储>浏览>受信任的根证书颁发机构>下一步>完成。

将此脚本插入httpd-xampp.conf 的底部

 <VirtualHost computername.domain:8080>
DocumentRoot "C:/xampp/htdocs"
</VirtualHost>

<VirtualHost computername.domain:4433>
DocumentRoot "C:/xampp/htdocs"
SSLEngine on
SSLCertificateFile "crt/computername.domain/server.crt"
SSLCertificateKeyFile "crt/computername.domain/server.key"
</VirtualHost>

重新启动 XAMPP 并尝试使用 https://computername.domain:4433 访问您的本地主机.

就是这样。我希望你能完成所有步骤。

关于ssl - XAMPP 中跨 LAN 的本地主机自签名证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55534785/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com