nginx location
ngnix location 转发请求
现在的需求是, 前后端分离, 用户请求前端地址,前端请求后端php的接口地址,用nginx做代理服务器, 根目录需要从前端请求, 然后转发api接口到php
具体nginx配置
server {
listen 8080;
server_name api.test.com;
charset utf-8;
#location / {
# try_files $uri $uri/ /index.php?$query_string;
#}
location / {
root /home/work/front/app;
index index.html index.htm;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /home/work/nginx/logs/nginx/api.test.log error;
sendfile off;
location ^~ /api {
alias /home/work/blog/public;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/home/work/php7.4/var/run/php7.4-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME /home/work/blog/public$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
}