hyperf 配置虛域名
小編是初體驗hyperf ,使用nginx配置虛擬域名,也是一步一步摸索過來。由於hyperf 是通過控制檯命令行啓動.與以往框架不同,hyperf並沒有index.php文件,hyperf的入口文件是bin/hyperf.php 按照官方文檔講,需要配置反向代理
第一步:在vhost目錄下新建配置文件
第二步:
採用反向代理配置虛擬域名
與以往的不同是,不需要root 指向根目錄,也不需要入口文件,貼出小編的配置文件代碼
upstream hyperf {
server 127.0.0.1:9501;
server 127.0.0.1:9502;
}
server
{
listen 80;
server_name hyperf-self-test.com;
include enable-php.conf;
location / {
# 將客戶端的 Host 和 IP 信息一併轉發到對應節點
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 轉發Cookie,設置 SameSite
proxy_cookie_path / "/; secure; HttpOnly; SameSite=strict";
# 執行代理訪問真實服務器
proxy_pass http://hyperf;
}
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log /home/wwwlogs/hyperf-self-test.access.log;
}
提醒:upstream 模塊必須在http裏面,server外面,否則會報錯
第三步:編輯/etc/hosts文件
第四步:
控制檯啓動hyperf
第五步:瀏覽器訪問
原來的0.0.0.0:9501也是可以訪問的