Skip to content

Commit 759f8c3

Browse files
author
chenchangqin
committed
develop#nginx反向代理及配置
1 parent 682d38d commit 759f8c3

File tree

7 files changed

+88
-4
lines changed

7 files changed

+88
-4
lines changed

.env

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@ MYSQL_ROOT_HOST=%
77
MYSQL_ROOT_PASSWORD=hSMZYpAGbNwVmERI
88

99
# hyperf
10-
HYPERF=./hyperf
10+
HYPERF_DIR=./hyperf
11+
12+
# nginx
13+
NGINX_DIR=./nginx
14+
HTTP_PORT=80
15+
HTTPS_PORT=443

.env.example

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@ MYSQL_ROOT_HOST=%
77
MYSQL_ROOT_PASSWORD=hSMZYpAGbNwVmERI
88

99
# hyperf
10-
HYPERF=./hyperf
10+
HYPERF_DIR=./hyperf
11+
12+
# nginx
13+
NGINX_DIR=./nginx
14+
HTTP_PORT=80
15+
HTTPS_PORT=443

docker-compose.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ networks:
55
driver: bridge
66

77
services:
8+
nginx:
9+
image: nginx:alpine
10+
container_name: hyper_nginx
11+
ports:
12+
- "${HTTP_PORT}:80"
13+
- "${HTTPS_PORT}:443"
14+
volumes:
15+
- ./hyperf:/etc/nginx/www/hyperf:rw
16+
- ${NGINX_DIR}/config/nginx.conf:/etc/nginx/nginx.conf:ro
17+
- ${NGINX_DIR}/config/conf.d:/etc/nginx/conf.d:ro
18+
- ${NGINX_DIR}/log:/var/log/nginx:rw
19+
restart: always
20+
networks:
21+
- hyperf
22+
tty: true
23+
824
redis:
925
container_name: hyper_redis
1026
image: redis:latest
@@ -49,7 +65,7 @@ services:
4965
container_name: hyperf
5066
image: hyperf/hyperf:latest
5167
volumes:
52-
- .:/opt/www
68+
- ./hyperf:/opt/www/hyperf
5369
ports:
5470
- "9501:9501"
5571
- "9502:9502"

hyperf/app/Model/User.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
declare (strict_types=1);
44
namespace App\Model;
55

6-
use Hyperf\DbConnection\Model\Model;
76
/**
87
* @property int $id
98
* @property string $username

nginx/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/log

nginx/config/conf.d/basic.com.conf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# 至少需要一个 Hyperf 节点,多个配置多行
2+
upstream hyperf {
3+
# Hyperf HTTP Server 的 IP 及 端口
4+
server hyperf:9501;
5+
server hyperf:9502;
6+
}
7+
8+
server {
9+
# 监听端口
10+
listen 80;
11+
# 绑定的域名,填写您的域名
12+
server_name basic.com;
13+
14+
location / {
15+
# 将客户端的 Host 和 IP 信息一并转发到对应节点
16+
proxy_set_header Host $http_host;
17+
proxy_set_header X-Real-IP $remote_addr;
18+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
19+
20+
# 转发Cookie,设置 SameSite
21+
proxy_cookie_path / "/; secure; HttpOnly; SameSite=strict";
22+
23+
# 执行代理访问真实服务器
24+
proxy_pass http://hyperf;
25+
}
26+
}

nginx/config/nginx.conf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
user nginx;
3+
worker_processes 1;
4+
5+
pid /var/run/nginx.pid;
6+
error_log /var/log/nginx/error.log warn;
7+
8+
events {
9+
worker_connections 1024;
10+
}
11+
12+
13+
http {
14+
include /etc/nginx/mime.types;
15+
default_type application/octet-stream;
16+
17+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
18+
'$status $body_bytes_sent "$http_referer" '
19+
'"$http_user_agent" "$http_x_forwarded_for"';
20+
21+
access_log /dev/null;
22+
#access_log /var/log/nginx/access.log main;
23+
24+
sendfile on;
25+
#tcp_nopush on;
26+
27+
keepalive_timeout 65;
28+
29+
#gzip on;
30+
31+
include /etc/nginx/conf.d/*.conf;
32+
}

0 commit comments

Comments
 (0)