nginx: v1.10.3
php: 5.6.37
前后端分离配置,可以有效处理vue-router的history模式,同时基于https
直接上配置吧
server {
listen 8088 ssl http2 ;
server_name web;
proxy_read_timeout 120;
proxy_send_timeout 120;
ssl_certificate ssl.crt;
ssl_certificate_key ssl.key;
access_log logs/web.8088.access.log main;
location ^~ /v1/ {
if (!-e $request_filename)
{
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location / {
root /webpath;
index index.htm index.html index.php;
try_files $uri $uri/ /index.html;
}
location ~ \.php/?.*$ {
add_header 'Access-Control-Allow-Origin' '$http_origin';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, content-type, x_requested_with';
add_header 'Access-Control-Allow-Methods' 'GET,POST,DELETE,PUT,OPTIONS';
if ($request_method = 'OPTIONS') {
return 206;
}
root /serverpath;
set $fastcgi_script_name2 $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") {
set $fastcgi_script_name2 $1;
set $path_info $2;
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_read_timeout 6000;
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name2;
fastcgi_param SCRIPT_NAME $fastcgi_script_name2;
}
}
网友评论