WordPress + Nginx 给我一个“403 forbidden”错误
WordPress + Nginx is giving me a "403 forbidden" error
我正在尝试在 Nginx 服务器上设置“使用 docker 图像安装”的 WordPress。
我 运行 docker 图像使用以下 docker-compose.yml
文件
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
现在,我正在尝试将 public 域 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 Forbidden 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 Bad Gateway
查看日志我得到以下错误
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;
}
}
我正在尝试在 Nginx 服务器上设置“使用 docker 图像安装”的 WordPress。
我 运行 docker 图像使用以下 docker-compose.yml
文件
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
现在,我正在尝试将 public 域 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 Forbidden 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 Bad Gateway
查看日志我得到以下错误
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;
}
}