关键词:域名、转发、反向代理、端口
1. 背景简介
只有一台VPS主机服务器,但想同时部署两个网站:
通过访问IP想打开一个页面,
访问已购买的域名想打开另一个页面。
2. 软件安装,与配置
Apache、Ngnix服务正常安装
其中Apache的监听端口改为:Listen 8080
,(vim /etc/httpd/conf/httpd.conf
)
其中Ngnix的监听端口改为:listen 8888
,(vim /etc/nginx/nginx.conf
)
重启服务
systemctl restart nginx.service
systemctl restart httpd.service
3. Ngnix服务端转发(域名,IP等)
Ngnix转发Apache配置:
vim /etc/nginx/conf.d/test.conf
加入
server {
# 监听80端口,一般不用改
listen 80;
# 将这里的example换成自己的域名
server_name 118.89.194.65;
location / {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 这里的http后面的url就是你访问你上方的域名代理的地址
proxy_pass http://127.0.0.1:8080/;
}
}
server {
# 监听80端口,一般不用改
listen 80;
# 将这里的example换成自己的域名
server_name lastinvent.online www.lastinvent.online *.lastinvent.online;
location / {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 这里的http后面的url就是你访问你上方的域名代理的地址
proxy_pass http://127.0.0.1:8888/;
}
最后,配置完成,再次重启服务
附:备用方案(暂时未用上)
参考:
Apache服务端转发(域名,IP等)
vim /etc/httpd/conf.d/httpdvhosts.conf
加入
<VirtualHost *:80>
ServerName localhost
# 设置访问转发的域名
ServerAlias xxxx.com
ProxyPreserveHost On
ProxyRequests Off
# 代理重定向地址
# (内网IP加端口 = 你的服务)
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>