nginx 伪静态配置
大约 1 分钟
docker打包
nginx-dockerfile
FROM nginx:alpine
WORKDIR /usr/share/nginx/html
COPY ./dist/ ./
# 配置 Nginx,如果需要配置反向代理,可以在这里添加配置
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
# 暴露 80 端口
EXPOSE 80
# 启动 Nginx 服务
CMD ["nginx", "-g", "daemon off;"]
dockerfile
FROM hyperf/hyperf:8.2-alpine-vedge-swoole-slim-v5
ENV TZ Asia/Shanghai
RUN apk add tzdata && cp /usr/share/zoneinfo/${TZ} /etc/localtime \
&& echo ${TZ} > /etc/timezone
WORKDIR /app
COPY . /app
RUN composer install --optimize-autoloader --prefer-dist
CMD ["php", "artisan", "octane:start", "--server=swoole", "--host=0.0.0.0", "--port=8089"]
docker-compose.yml
services:
app:
# image: registry.cn-hangzhou.aliyuncs.com/orangbus/math-api
build:
context: .
privileged: true
restart: unless-stopped
ports:
- "8089:8089"
volumes:
- ./.env:/app/.env
- ./logs:/app/storage/logs
network_mode: bridge
command: php artisan octane:start --server=swoole --port=8089
queue:
image: registry.cn-hangzhou.aliyuncs.com/orangbus/math-api
restart: unless-stopped
volumes:
- .env:/app/.env
command: php artisan queue:work --tries=3
schedule:
image: registry.cn-hangzhou.aliyuncs.com/orangbus/math-api
restart: unless-stopped
volumes:
- .env:/app/.env
command: php artisan schedule:work
云效配置

nginx-api
server {
listen 80;
listen [::]:80;
server_name domain.com;
server_tokens off;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /index.php {
try_files /not_exists @octane;
}
location / {
try_files $uri $uri/ @octane;
}
location @octane {
set $suffix "";
if ($uri = /index.php) {
set $suffix ?$query_string;
}
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Scheme $scheme;
proxy_set_header SERVER_PORT $server_port;
proxy_set_header REMOTE_ADDR $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_pass http://127.0.0.1:8000$suffix; # 修改为自己的地址
}
}
nginx-admin
server {
listen 80;
server_name orangbus.cn;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
location /admin {
proxy_pass https://api.laravel.com;
# proxy_redirect off;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# laravel-echo-serve 配置
location /socket.io {
proxy_pass http://localhost:6001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}
thinkphp
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
}
}
vue
location / {
try_files $uri $uri/ /index.html;
}
反向代理配置
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://backend_server;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
负载均衡配置
http {
# 设置Nginx的全局配置
# 定义上游服务器
upstream backend {
server backend1.example.com weight=3;
server backend2.example.com weight=2;
}
# 配置HTTP服务器
server {
listen 80;
server_name example.com;
# 负载均衡配置
location / {
proxy_pass http://backend;
}
}
}