【发布时间】:2019-01-04 02:58:59
【问题描述】:
我目前正在使用一个使用 Nginx 提供的 javascript 框架,例如在以下 url 上
www.myjsapp.com
我也在使用 Laravel 5.6 来构建 API。
我希望能够在以下 URL 上提供 Laravel API,而不是构建 2 个主机,一个用于 JS 应用程序,一个用于 Laravel。
www.jsapp.com/api
这可能吗,还是我必须始终使用 2 台主机?
myjsappcom的nginx服务器块如下;
server {
listen 80;
listen 443 ssl http2;
server_name .myjsapp.com;
root "/home/project/myjsapp";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
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 /var/log/nginx/myjsapp.com-error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$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;
}
ssl_certificate /etc/nginx/ssl/myjsapp.com.crt;
ssl_certificate_key /etc/nginx/ssl/myjsapp.com.key;
}
【问题讨论】:
-
在 nginx 中为你的 nodejs 创建一个反向代理,然后你将两者都放在同一个域下。
-
@N.B.这是在 Nginx 中完成的吗?
-
是的。在 Nginx 中。你可以用谷歌搜索配置示例。
标签: php laravel nginx nginx-location