One: As the system comes with Apache environment MacOX, so we configured with Apache on Mac systems.
Mac System: 10.14.4
Two: Start Apache
Start at the terminal input: sudo apachectl start
verification in your browser and enter " HTTP: // localhost " It works show that the server has successfully started up!
In Mac under Apache's default root directory under "/ Library / WebServer / Documents /", you can also set up their own folder, only you need to modify it in the Apache configuration.
Three: Configure server
1, in a new folder in finder
2, a terminal is opened, switching the working directory: cd / etc / apache2
3, backup files, need only be performed once: sudo cp httpd.conf httpd.conf.bak (This step is just to back up what)
If the operator error! You can use the command to restore the backup httpd.conf file: sudo cp httpd.conf.bak httpd.conf
4, with vim edit the httpd.conf file when the file httpd.conf Apache configuration file: sudo vim httpd.conf
6, after finding Options FollowSymLinks: modify the Options Indexes FollowSymLinks, Indexes add a word between two words.
7、接下来查找php,:/php,定位到图中位置:
8、将这句代码前面的#去掉。最后 Esc退出, :wq保存并退出。
9、切换工作目录:cd /etc
10、拷贝php.ini文件:sudo cp php.ini.default php.ini
重新启动apache服务器
在终端输入:sudo apachectl -k restart
cd desktop/SSL
1. 自签名证书
(1) 在SSL文件夹中生成私钥 生成rsa私钥,2048位强度,server.key是秘钥文件名
openssl genrsa -out server.key 2048
openssl req -new -sha256 -x509 -days 365 -key server.key -out server.crt
Common Name应该与域名保持一致(如我的电脑搭建的服务器IP地址为192.168.1.112)
2. 配置Apache服务器SSL
(1) 放入证书
将server.crt和server.key两个文件拷贝
放到/etc/apache2/目录 (Finder中点击前往文件夹/etc即可打开etc文件夹)
(2) 修改配置文件
若是配置文件无法修改 只需要把途中位置改掉就好
-
编辑
/etc/apache2/httpd.conf
文件
找到去掉下面前边的注释#号LoadModule ssl_module libexec/apache2/mod_ssl.so
Include /private/etc/apache2/extra/httpd-vhosts.conf
Include /private/etc/apache2/extra/httpd-ssl.conf
LoadModule socache_shmcb_module libexec/apache2/mod_socache_shmcb.so -
打开
/etc/apache2/extra/httpd-ssl.conf
文件
去掉以下两项注释并检查是否与之前安装私钥和证书的路径一致SSLCertificateFile "/private/etc/apache2/server.crt"
SSLCertificateKeyFile "/private/etc/apache2/server.key" - 编辑/etc/apache2/extra/httpd-vhosts.conf文件
在<VirtualHost *:80> .....</VirtualHost>后面添加一段如下内容:
<VirtualHost *:443>
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /private/etc/apache2/server.crt
SSLCertificateKeyFile /private/etc/apache2/server.key
ServerName 192.168.1.112 DocumentRoot "/Library/WebServer/Documents" </VirtualHost>
注意ServerName填写域名与所需访问一致
(3) 重启服务器
sudo apachectl restart
访问https://192.168.1.112/
提示不安全什么的(因为自己的证书没添加到浏览器信任列表),继续访问