我希望使用反向代理(
proxy_pass
)配置nginx,该反向代理路由到我的应用程序中的localhost:3000
和location
/blog
它路由到wordpress。
我的配置文件是:
server {
listen [::]:443 ssl ipv6only=on;
listen 443 ssl;
#begin ssl_certificates
.....
#end ssl_certificates
server_name example.com;
root /var/www/example.com; #WP files are in /var/www/example.com/blog
index index.php;
location /blog {
alias /var/www/example.com/blog; #the WP files are in /var/www/example.com/blog also tried /var/www/example.com
index index.php;
try_files $uri $uri/ /blog/index.php?$args;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # Adjust the version based on your PHP-FPM version
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
location ~ /\.ht {
deny all;
}
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
}
}
server {
listen 80;
listen [::]:80 ipv6only=on;
server_name example.com;
location / {
proxy_pass http://localhost:3000;
}
}
当我转到路径
https://example.com/blog
时,它显示 404。
我尝试的其他配置是将 WP 文件移动到
/var/www/example.com
,但我不认为这是问题,因为实际上没有重定向到静态文件。
我尝试使用两个
proxy_pass
并且确实有效:
...
location / {
proxy_pass http://localhost:3000;
}
location /blog {
proxy_pass http://localhost:9000;
}
...
如果没有解决方法,您是否知道任何其他可以像这样工作的 CMS?
问题在于文件夹中的许可证对于它正在读取的应用程序来说不正确。因此找不到它。