这是我网站的总体默认配置。我的wordpress位于一个名为Blog的子目录中。
使用已安装fpm的php 7.2。
我为sub dir尝试了多个位置块,或者我得到了当前通过配置获得的东西,即重定向。否则我会收到403错误。
NGINX错误从日志输出(它试图从我的主目录加载/ static / xxx东西,这不应该发生)[它似乎没有试图在博客文件夹下加载index.php]:
2019/02/25 19:43:22 [error] 5026#0: *28577883 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: x.x.x.x, server: www.xx.com, request: "GET /blog/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.xx.com"
2019/02/25 19:43:22 [error] 5026#0: *28577884 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: x.x.x.x, server: www.xx.com, request: "GET /blog/static/js/webim.config.js HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.xx.com", referrer: "https://www.xx.com/blog/"
2019/02/25 19:43:22 [error] 5026#0: *28577885 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: x.x.x.x, server: www.xx.com, request: "GET /blog/static/js/websdk.shim.js HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.xx.com", referrer: "https://www.xx.com/blog/"
2019/02/25 19:43:22 [error] 5026#0: *28577883 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: x.x.x.x, server: www.xx.com, request: "GET /blog/static/js/webim.config.js HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.xx.com", referrer: "https://www.xx.com/blog/"
2019/02/25 19:43:22 [error] 5026#0: *28577883 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: x.x.x.x, server: www.xx.com, request: "GET /blog/static/js/websdk.shim.js HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.xx.com", referrer: "https://www.xx.com/blog/"
这是我的nginx配置:
(网站被屏蔽)
worker_processes 4;
error_log /usr/local/nginx/logs/error.log;
pid /usr/local/nginx/nginx.pid;
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections 65535;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /usr/local/nginx/logs/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
server_name www.xx.com xx.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name www.xx.com;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
access_log /usr/local/nginx/logs/xx.log;
ssl_certificate /usr/local/nginx/cert/XXXX.pem; XX
ssl_certificate_key /usr/local/nginx/cert/XXXX.key; XX
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers XX
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
proxy_connect_timeout 60;
proxy_read_timeout 60;
proxy_send_timeout 60;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
root /html/pc;
if ($http_user_agent ~* "(mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)"){
root /html/wap;
}
index index.html index.php;
try_files $uri $uri/ /index.html;
}
location /blog {
root /html;
index index.php index.html index.htm;
try_files $uri $uri/ /blog/index.php;
}
location ~ .php$ { ## Execute PHP scripts
# if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
fastcgi_intercept_errors on;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
当我将此位置块用于/ blog时,出现403授权错误
location /blog {
alias /html;
index index.php index.html index.htm;
try_files $uri $uri/ /blog/index.php;
}