使用hyperf的时候发现它监听9501端口,然后这样需要ip+port方式去访问,但是这样对用户而言有点不太友好,如果我们还有域名,可以做一个反向代理避免端口直接写出来。

找了找网上别人写的例子,感觉都太不细致了,还是自己写一个吧。

例子如下:

1.查找  sudo apt search apache2

Sorting... Done
Full Text Search... Done
apache2/focal-updates,focal-security,now 2.4.41-4ubuntu3.1 amd64 [installed]
Apache HTTP Server

2.安装  sudo apt-get install apache2

3.查看 apache2 状态

systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2021-06-18 13:26:06 CST; 2min 20s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 41948 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 41952 (apache2)
Tasks: 6 (limit: 19023)
Memory: 17.8M
CGroup: /system.slice/apache2.service
├─41952 /usr/sbin/apache2 -k start
├─41959 /usr/sbin/apache2 -k start
├─41960 /usr/sbin/apache2 -k start
├─41961 /usr/sbin/apache2 -k start
├─41962 /usr/sbin/apache2 -k start
└─41963 /usr/sbin/apache2 -k start

4.启动 apache2 如有必要关闭 nginx

systemctl stop nginx.service

5.开启各种重写反向代理模块

sudo a2enmod rewrite

提示我已经开了(因为以前开过点这里)

Module rewrite already enabled
sudo a2enmod proxy
Enabling module proxy.
To activate the new configuration, you need to run:
systemctl restart apache2
sudo a2enmod proxy_http
Considering dependency proxy for proxy_http:
Module proxy already enabled
Enabling module proxy_http.
To activate the new configuration, you need to run:
systemctl restart apache2

按它说的重启一下apache2

systemctl restart apache2

重启完成查看已经安装的Module

apache2ctl -M |grep pro
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
proxy_module (shared)
proxy_http_module (shared)
apache2ctl -M |grep rew
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
rewrite_module (shared)

6.重启apache2

sudo /etc/init.d/apache2 restart
Restarting apache2 (via systemctl): apache2.service.

7.做反向代理的一个vhost配置

编辑 /etc/hosts

127.0.0.1 local.hyperf.com

创建并编辑 /etc/apache2/sites-enabled/local.hyperf.com.conf

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName local.hyperf.com ServerAdmin local.hyperf.com
DocumentRoot /var/www/html/hyperf
ProxyPreserveHost On
ProxyPass / http://0.0.0.0:9501/
ProxyPassReverse / http://0.0.0.0:9501/ # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet

8.重启apache2

sudo /etc/init.d/apache2 restart
Restarting apache2 (via systemctl): apache2.service.

9.访问 http://local.hyperf.com/ 发现成功

ubuntu 下做反向代理给hyperf使用的更多相关文章

  1. ubuntu下配置反向代理

    1. 环境 ubuntu:Ubuntu 13.04 x86-64 apache2: 2.2.22-6ubuntu5.1 amd64 2. 配置 2.1  配置应用 增加监听端口 打开/etc/apac ...

  2. wsl 2 unbuntu 部署 asp.net core 使用 nginx 做反向代理,调试文件上传失败

    继上一篇 asp.net core 3.1多种身份验证方案,cookie和jwt混合认证授权 的公司内部项目上线后发现文件上传功能有问题. 上传的文件超过50M以后前端就报错了,没有状态返回,也没有响 ...

  3. Nginx做反向代理总是被系统kill

    公司使用Nginx做反向代理,以前都挺正常的,最近不知怎么回事总是无端被系统kill,而在nginx错误日志中也没有信息输出. 网上查了很多资料,也没什么靠谱的回答,唯一觉得有点关联的就是linux ...

  4. iis7.5做反向代理配置方法实例图文教程

    网络上好多开场的文章就说了好多的原理之类的这里我们直接开始配置.不过也要简单说下win下配置反向代理只有IIS7以上的版本才可以实现这个功能,在这里我们使用WINDOWS2008 R2来做为测试 20 ...

  5. apache做反向代理

    实验目的 通过apache实现反向代理的功能,类似nginx反向代理和haproxy反向代理 环境准备 逻辑架构如下 前端是apche服务器,监听80端口,后端有两台web服务器,分别是node1和n ...

  6. 生产环境中nginx既做web服务又做反向代理

    一.写对于初入博客园的感想 众所周知,nginx是一个高性能的HTTP和反向代理服务器,在以前工作中要么实现http要么做反向代理或者负载均衡.尚未在同一台nginx或者集群上同时既实现HTTP又实现 ...

  7. asp.net core 托管到windows服务,并用iis做反向代理

    使用NSSM把.Net Core部署至 Windows 服务   为什么部署至Windows Services 在很多情况下,很少会把.Net Core项目部署至Windows服务中,特别是Asp.n ...

  8. 转载:Nginx做反向代理和负载均衡时“X-Forwarded-For”信息头的处理

    转载自:https://blog.51cto.com/wjw7702/1150225 一.概述 如今利用nginx做反向代理和负载均衡的实例已经很多了,针对不同的应用场合,还有很多需要注意的地方,本文 ...

  9. nginx做反向代理并防盗链

    nginx做反向代理真的非常简单,只需设置location+proxy_pass即可. 防盗链配置有些复杂,需要注意的地方: 在防盗链的location中需要再设置一下proxy_pass(在这里走了 ...

  10. 用nginx做反向代理来访问防外链图片

    用nginx做反向代理来访问防外链图片 女儿的博客从新浪搬到wordpress后,发现原来博客上链接的新浪相册的图片都不能访问了,一年的博客内容,一个个去重新上传图片,修正链接也是个大工程.还是得先想 ...

随机推荐

  1. PyJWT 和 python-jose 在处理JWT令牌处理的时候的差异和具体使用

    PyJWT 和 python-jose 是两个用于处理 JSON Web Tokens (JWT) 的 Python 库.它们都有助于生成.解码.验证和管理 JWT,但它们在功能范围和设计哲学上有一些 ...

  2. Docker的数据卷与数据卷容器操作

    一.数据卷 数据卷(Data Volumes)是一个可供容器使用的特殊目录,它将主机操作系统目录直接映射进容器,类似于Linux中的mount动作. 数据卷可以提供很多有用的特性: 数据卷可以在容器之 ...

  3. Docker高级篇:实战Redis集群!从3主3从变为4主4从

    通过前面两篇,我们学会了三主三从的Redis集群搭建及主从容错切换迁移,随着业务增加,可能会有主从扩容的,所以,本文我们来实战主从扩容 PS本系列:<Docker学习系列>教程已经发布的内 ...

  4. python configparser 创建ini文件,动态读取与修改配置文件,以及保存与读取字符串与QColor类型的配置

    # 动态配置所需 from import ConfigParser # 获取系统语系所需 import locale # QColor 类型的传参所需 from PyQt6.QtGui import ...

  5. 图穷匕见-所有反DDD模式都是垃圾

    本文书接上回<主观与客观,破除DDD凭经验魔咒>,关注公众号(老肖想当外语大佬)获取信息: 最新文章更新: DDD框架源码(.NET.Java双平台): 加群畅聊,建模分析.技术实现交流: ...

  6. 测距技术 超声波、毫米波、激光雷达LIDAR

    超声波 技术成熟,成本之选 声波传输慢,高速时误差大 超声波雷达有40kHz.48kHz和58kHz三种,频率越高,灵敏度越高,探测角度越小.在工作状态,通过收发超声波,超声波雷达能以1-3cm精度测 ...

  7. Redis 高可用方案原理初探

    redis 参考目录: 生产级Redis 高并发分布式锁实战1:高并发分布式锁如何实现 https://www.cnblogs.com/yizhiamumu/p/16556153.html 生产级Re ...

  8. python学习教材选哪个

    python语言俨然成为当今最流行的国际语言,无论你是做AI的还是非AI,大家都在用python语言,各种平台也都开始支持python,现在连文科生都在学习python语言了,甚至很多表哥表姐的工作都 ...

  9. TS2Vec: 面向通用的时间序列表示《TS2Vec: Towards Universal Representation of Time Series》(时间序列、对比学习、多尺度特征(池化操作)、分层对比、上下文一致性(时间戳掩码+随机裁剪))

    今天是2024年5月22日,10:24,今天看这篇经典的论文(如果你问我为什么最近频繁看论文,因为我的创新点无了,要找创新点+太菜了,菜就多看多学). 论文:TS2Vec: Towards Unive ...

  10. Angular 18+ 高级教程 – Angular Configuration (angular.json)

    前言 记入一些基本的配置. Setup IP Address.SSL.Self-signed Certificate 如果你对 IP Address.SSL.Self-signed Certifica ...