[英]WordPress + Nginx is giving me a "403 forbidden" error
我正在尝试在 Nginx 服务器上设置 WordPress“使用 docker 映像安装”。
我使用以下docker-compose.yml
文件运行 docker 映像
version: "3"
services:
wordpress_app:
image: wordpress:latest
restart: always
container_name: wordpress_app
environment:
WORDPRESS_DB_HOST: mysql_server:3306
WORDPRESS_DB_USER: db_username
WORDPRESS_DB_PASSWORD: db_password
WORDPRESS_DB_NAME: db_name
depends_on:
- mysql_server
volumes:
- /data/wordpress_app/public_html:/var/www/html
ports:
- 8000:80
- 8001:443
mysql_server:
image: mysql:latest
restart: always
container_name: mysql_server
environment:
MYSQL_DATABASE: db_name
MYSQL_USER: db_username
MYSQL_PASSWORD: db_password
MYSQL_ROOT_PASSWORD: root_password
volumes:
- mysql_server_data:/var/lib/mysql
volumes:
mysql_server_data:
networks:
default:
external:
name: nginx-network
现在,我正在尝试将公共域usa.mydomain.com
代理到localhost:8000
server {
listen 80;
server_name usa.mydomin.com;
root /var/www/html;
access_log off;
error_log /var/log/nginx/usa.mydomain.com-error.log;
index index.html index.php;
location / {
# First attempt to serve request as file, then as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$args;
}
# pass the PHP scripts to FastCGI server listening on localhost:8000
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass localhost:8000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
但是,当我浏览 usa.mydomain.com 我得到
403 禁止nginx/1.14.0 (Ubuntu)
我该如何纠正这个错误?
我把Nginx改成如下配置
server {
listen 80;
server_name usa.mydomin.com;
#root /var/www/html; # <<<<< REMOVED THIS
root /data/wordpress_app/public_html; # <<<<< ADDED THIS
access_log off;
error_log /var/log/nginx/usa.mydomain.com-error.log;
index index.html index.php;
location / {
# First attempt to serve request as file, then as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$args;
}
# pass the PHP scripts to FastCGI server listening on localhost:8000
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass localhost:8000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
但现在我得到
502错误的网关
查看日志我收到以下错误
2020/10/16 15:22:58 [error] 1475#1475: *68 upstream sent unsupported FastCGI protocol version: 72 while reading response header from upstream, client: MyIpAddress, server: usa.mydomain.com, request: "GET / HTTP/1.1", upstream: "fastcgi://[::1]:8000", host: "usa.mydomain.com"
2020/10/16 15:22:58 [error] 1475#1475: *68 upstream sent unsupported FastCGI protocol version: 72 while reading response header from upstream, client: MyIpAddress, server: usa.mydomain.com, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:8000", host: "usa.mydomain.com", referrer: "http://usa.mydomain.com/"
我该如何解决这个问题?
经过几天的尝试,使用以下设置修复了该应用程序。 我希望这能节省一些人的时间
server {
listen 80;
server_name usa.mydomain.com;
root /data/wordpress_app/public_html;
access_log off;
error_log /var/log/nginx/wordpress_app-error.log;
index index.html index.php;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
location / {
try_files $uri $uri/ /index.php?$args;
proxy_pass http://localhost:8000;
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;
}
}
我的具体问题:通过作曲家安装 SearchWP 插件后,我只获得了 SearchWP 插件资产的 403。 我正在使用 Docksal 进行基于 WordPress 的本地 docker 开发。
解决方案:
fin bash
和ls -la
chmod -R 755 searchwp
修复目标目录的权限并解决了问题。希望它可以帮助某人。
谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.