nginx配置
2026年12月5日小于 1 分钟
本地电脑开发调试配置
示例:
1解析本地开发调试域名
在本地电脑C:\Windows\System32\drivers\etc\HOSTS中解析
127.0.0.1 dev.laravel.com
2docker容器中配置nginx
usr/local/nginx/conf/vhost/api.youhujun.com.conf
提示
基于lnmp2.4搭建的环境
server
{
#侦听80端口
listen 80;
server_name dev.laravel.com;
index index.html index.htm index.php;
root /data/wwwroot/youhujun.com/api.youhujun.com/public;
include enable-php-pathinfo.conf;
location /
{
try_files $uri $uri/ /index.php?$query_string;
}
}检测配置
/usr/local/nginx/sbin/nginx -t重启nginx
pkill -HUP nginx测试
curl -I -H "Host: dev.laravel.com" http://127.0.0.1/3配置反向代理
基于本地宝塔
- 网站 → 添加站点,域名填
dev.laravel.com,PHP 版本选「纯静态」(不要选 PHP,反代不吃本地 PHP)。 - 进该站点 → 设置 → 反向代理 → 添加反向代理。
- 目标 URL 填
http://127.0.0.1:8080,发送域名填$host。
非宝塔配置
server {
listen 80;
server_name dev.laravel.com;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 60s;
proxy_send_timeout 60s;
}
}