apache和nginx设置反向代理


title: apache和nginx设置反向代理
date: 2018-2-4
author: giantbranch
tags:

  • apache
  • nginx

apache

a2enmod proxy
a2enmod proxy_http
a2enmod proxy_connect

之后编辑/etc/apache2/mods-available/proxy.conf

<Proxy *>
		Order allow,deny
		Allow from all
</Proxy>

设置站点的配置文件,以代理本地3000端口为例,那当我们访问XXXXX.giantbranch.cn就可以访问本地3000端口的网站了

<VirtualHost *:80>
		......
		
        ServerName XXXXX.giantbranch.cn
        ProxyPass / http://127.0.0.1:3000/
        ProxyPassReverse / http://127.0.0.1:3000/
		
		......
</VirtualHost>

最后重启(下面以ubuntu为例)

service apache2 restart

有些系统可以这样

systemctl restart apache2

nginx

这个就简单多了,直接创建一个站点配置文件,那么访问haha.giantbranch.cn,就可以访问本地的3001端口了

server {
	......
        listen 80;
        server_name haha.giantbranch.cn;

        location / {
                proxy_pass http://localhost:3001;
        }
		
		......
}

当然重启一下

service nginx restart
原文地址:https://www.cnblogs.com/cnsec/p/13286494.html