在nginx上部署PHP和react js应用程序



我正在尝试在我的ubuntu 18.04服务器上的Nginx上运行reactjs应用程序和PHP应用程序。 Reactjs 应用程序运行良好,但我无法运行 PHP 应用程序。 我已经为两个应用程序添加了两个服务器块,但无法运行PHP应用程序,这实际上是我对react js应用程序的api/服务。

在这方面的任何帮助将不胜感激。

这是我对 react js 应用程序的 nginx 配置:

server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html/qurancom-reactjs;        
index index.html index.htm index.nginx-debian.html;
server_name 3.16.130.108;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:3000;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
                                                                                                                    }

这是我的PHP应用程序nginx服务器块配置:

server {
listen 80;
listen [::]:80;
root /var/www/html/quran-app-services/api;
index index.php index.html index.htm index.nginx-debian.html;
server_name 3.16.130.108;
location / {
try_files $uri $uri/ =404;
}
}

谢谢

两个配置的侦听端口均为 80。此外,反应和 PHP 配置都是针对/的。

尝试为 PHP 设置不同的侦听端口,并将位置更改为/api

此外,请尝试将错误日志和访问日志添加到服务器配置,以便可以调查服务器何时返回 500 或 405 错误

error_log /var/log/nginx/laravel-app-error.log;
access_log /var/log/nginx/laravel-app-access.log;

这是Laravel项目的工作服务器配置,您可以参考

server {
listen     90;
server_name <server ip or hostname>;
charset utf-8;
root /var/www/html/laravel/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.php index.html index.htm;
# Always serve index.html for any request
location /api {
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; }
error_page 404 /index.php;
location ~ .php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /.(?!well-known).* {
deny all;
}
error_log /var/log/nginx/laravel-app-error.log;
access_log /var/log/nginx/laravel-app-access.log;
}

最新更新