thinkphp5 + vue 配置
1server { 2 3 listen 80; 4 listen [::]:80; 5 6 # For https 7 listen 443 ssl; 8 listen [::]:443 ssl; 9 ssl_certificate /etc/nginx/ssl/xxx.pem; 10 ssl_certificate_key /etc/nginx/ssl/xxx.key; 11 if ($scheme = 'http') 12 { 13 return 301 https://$server_name$request_uri; 14 } 15 16 #auth 17 auth_basic on; 18 auth_basic_user_file /etc/nginx/ssl/.auth; 19 20 #gzip 21 gzip on; 22 gzip_comp_level 6; 23 gzip_min_length 1024; 24 gzip_buffers 32 4K; 25 gzip_types application/javascript text/css; 26 27 server_name xxx; root /var/www/xxx/dist; 28 index index.php index.html index.htm; 29 30 # For vue 31 location / { 32 try_files $uri $uri/ /index.html; 33 } 34 35 location ~* \.(jpg|jpeg|png|gif|js|css|mtn)$ { 36 expires 1d; 37 } 38 39 # For thinkphp5 40 location ~ ^/api/ { 41 if (!-e $request_filename) { 42 rewrite ^/api/(.*)$ /index.php?s=/$1 last; 43 } 44 } 45 46 location ~ \.php$ { 47 root /var/www/xxx/php/public; 48 fastcgi_pass php-upstream; 49 fastcgi_index index.php; 50 fastcgi_buffers 16 16k; 51 fastcgi_buffer_size 32k; 52 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 53 #fixes timeouts 54 fastcgi_read_timeout 600; 55 include fastcgi_params; 56 } 57 58 59 location ~ /\.ht { 60 deny all; 61 } 62 63 64 location /.well-known/acme-challenge/ { 65 root /var/www/letsencrypt/; 66 log_not_found off; 67 } 68 69 70 error_log /var/log/nginx/xxx_error.log; 71 access_log /var/log/nginx/xxx_access.log; 72}
vue部分还可以:
if (!-d $request_filename) {
rewrite ^/(.+)/$ /$1 permanent;
}