我是 Nginx 和服务器配置的新手。我尝试使用同一个域部署 Wordpress Web 和 Angular 2 Web 应用程序(每个项目位于不同的文件夹/路径中),并由 Nginx 配置。对于http://example.com我需要加载 wordpress 网站,并且http://example.com/demoAngular 应用程序。
经过一番研究和尝试,我可以让 Angular 应用程序单独运行,并在根部分设置路径,但是当我更改 Nginx 配置文件以包含 Wordpress 的位置块和根时,Web 可以运行,但 Angular 应用程序找不到 js 和 css 文件。此外,Wordpress Web 有无法找到的联系和隐私政策页面(http://example.com/contact和http://example.com/privacy-policy)。
项目路径为:
/var/www/dashboard/dist/angularApp/
/var/www/wordpressWebsite
我当前的 Nginx 配置文件包含:
server {
server_name example.com www.example.com;
root /var/www/wordpressWebsite;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location /demo {
alias /var/www/dashboard/dist/angularApp/;
try_files $uri $uri/ /index.html;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
希望有人能帮助我,提前谢谢您!