前言
在涉及到使用Nginx代理多个Apache2项目时,不可避免需要Apache2使用不同的端口才能正常访问。
而且不知道什么原因,好像Apache2开启了HSTS严格认证,使得Nginx只能代理https,代理http的话会出现无法访问的情况。无奈~
这边记录一下学习过程。
步骤
1.修改Apache2监听端口
Apache2的监听端口配置文件为 ports.conf
1 |
vim /etc/apache2/ports.conf |
增加自己需求的端口:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf
Listen 8081
Listen 8082
<IfModule ssl_module>
Listen 444
Listen 445
</IfModule>
<IfModule mod_gnutls.c>
Listen 444
Listen 445
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
|
此时就监听了http的 8081
和 8082
,https的 444
和 445
。
2.修改Apache的网站配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<VirtualHost *:8081>
DocumentRoot /var/www/***
</VirtualHost>
<VirtualHost *:444>
DocumentRoot /var/www/***
SSLEngine on
SSLCertificateFile /***/***.crt
SSLCertificateKeyFile /***/***.key
SSLCertificateChainFile /***/***.crt
<Directory /var/www/***>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<FilesMatch "\.(?:cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>
|
正常来说,本地的反向代理使用http就行,不建议代理https。
3.修改Nginx的网站配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#https部分配置
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
root /var/www/***
server_name yydnas.cn www.yydnas.cn;
index index.php index.html index.htm;
ssl_certificate /etc/xxx/xxx.pem
ssl_certificate_key /etc/xxx/xxx.key
********省略********
location / {
proxy_pass_header Server;
proxy_pass https://localhost:444; #或者http://localhost:8081
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
|
4.载入配置
1 2 |
systemctl restart apache2 systemctl restart nginx |
此时应该就可以访问网站了。
总结
学习的过程挺好玩的,主要是网上关于apache2的教程不是很多,很多东西都要自己一个个尝试,体验的是一个过程。
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)