前端项目请求接口的base_url是当前网站的主域名,为了测试我打包后放在了本地phpstudy_pro配置的服务中,结果导致请求404,因为多人项目我就在本地的Nginx 中做了跨域代理,记录一下
1.Nginx反向代理
打开 当前网站的配置文件 D:\phpstudy_pro\Extensions\Nginx1.15.11\conf\vhosts\0localhost_8081.conf
location / {
proxy_pass http://192.168.124.47:8089;
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;
# 如果需要支持跨域
add_header Access-Control-Allow-Origin *;
}
2.Apache反向代理
1.打开文件 D:\phpstudy_pro\Extensions\Apache2.4.39\conf\httpd.conf
放开
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_module modules/mod_proxy.so
2.打开当前网站的配置文件 D:\phpstudy_pro\Extensions\Apache2.4.39\conf\vhosts\0localhost_8081.conf
<VirtualHost _default_:8080>
DocumentRoot "D:/phpstudy_pro/WWW"
FcgidInitialEnv PHPRC "D:/phpstudy_pro/Extensions/php/php7.3.4nts"
AddHandler fcgid-script .php
FcgidWrapper "D:/phpstudy_pro/Extensions/php/php7.3.4nts/php-cgi.exe" .php
ProxyRequests Off //关闭正向代理
<Directory "D:/phpstudy_pro/WWW">
Options FollowSymLinks ExecCGI
AllowOverride All
Require all granted
DirectoryIndex index.php index.html
</Directory>
<Directory "D:/phpstudy_pro/WWW/workspace">
Options FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
RewriteBase /workspace/
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /workspace/index.html [L]
</Directory>
# ✅ 只保留 ProxyPass / ProxyPassReverse 等允许在 Location 中的指令
<LocationMatch "^/(api|upload|client|feishu)(/.*)?$">
ProxyPass http://192.168.124.20:8089/
</LocationMatch>
ErrorDocument 400 /error/400.html
ErrorDocument 403 /error/403.html
ErrorDocument 404 /error/404.html
ErrorDocument 500 /error/500.html
# 其他错误页...
</VirtualHost>

2305

被折叠的 条评论
为什么被折叠?



