Nginx配置,用于将Wordpress设置为主页,但/列出节点中的页面



(我没有太多设置nginx配置的知识(

嗨,我想将我的 aws nginx 配置设置为

我想打开

www.example.com or  
www.example.com/contact or  
www.example.com/about  
as my Wordpress Pages  

但我也有我的节点/ejs 页面。

我的节点 API 就像/类别、/国家

所以如果我想去

www.example.com/list/categories 

它应该打开由 Node 服务的我的页面

这是我的配置(在nginx/sites-available/default中(用于为我的wordpress页面提供服务-


server {
listen 80;
listen [::]:80;
root /var/www/html/wordpress;
index index.php index.html index.htm;
server_name example.com www.example.com;
client_max_body_size 100M;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

它工作正常,当我点击IP时显示我的WordPress网站,但是

现在

我默认在此WordPress服务器块下方添加新的服务器块(用于服务节点页面(,因此它现在看起来像:


server {
listen 80;
listen [::]:80;
root /var/www/html/wordpress;
index index.php index.html index.htm;
server_name example.com www.example.com;
client_max_body_size 100M;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

server {
listen 80;
server_name localhost;

location /list {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}

我可以打开wordpress作为我的主页或 example.com/about 等。

但是当我打开 example.com/list/categories 或任何其他节点 API 时,我得到 BadGateway 502

我得到了解决方案。这是对我有用的nginx配置。

listen [::]:80;
root /var/www/html/wordpress;
index index.php index.html index.htm;
client_max_body_size 100M;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ ^/(something|somethingelse|javascripts|stylesheets|images) {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

不要忘记像我一样在此配置中添加文件夹(存在于公用文件夹中(。

从您打开example.com/list/categories开始,您的配置应如下所示:

server {
listen 80;
listen [::]:80;
root /var/www/html/wordpress;
index index.php index.html index.htm;
server_name example.com www.example.com;
client_max_body_size 100M;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location /list {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}

最新更新