使用Nginx代理安装Wordpress子目录

Im trying to setup Wordpress (running in php-fpm) with Nginx as a reverse proxy with the following configuration.

I have installed wordpress in /var/www/public/blog.

root@1088e33c9d2d:/srv# ls /var/www/public/blog/
index.php    readme.html      wp-admin        wp-comments-post.php  wp-config-sample.php  wp-cron.php  wp-links-opml.php  wp-login.php  wp-settings.php  wp-trackback.php
license.txt  wp-activate.php  wp-blog-header.php  wp-config.php     wp-content        wp-includes  wp-load.php        wp-mail.php   wp-signup.php    xmlrpc.php

Nginx.conf,

server {
  server_name _;

  listen 80 default_server;
  listen [::]:80 default_server;

  access_log syslog:server=unix:/dev/log;
  error_log syslog:server=unix:/dev/log debug;

  root /var/www/public;

  # Default location settings
  location / {
    index   index.html index.htm index.php;
  }

  location /blog {
    index   index.html index.htm index.php;
    try_files $uri $uri/ /blog/index.php?$args;
  }

  location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
  }

  # Set expires time for browser caching for media files
  location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
    access_log off;
    log_not_found off;
    expires max;
  }

  # Set expires time for js and css files
  location ~* \.(js|css)$ {
    expires 24h;
    add_header Pragma public;
    add_header Cache-Control "public";
    log_not_found off;
  }

  # Block serving of hidden files
  location ~ /\. {
    deny  all;
    access_log off;
    log_not_found off;
  }

  location ~ /\.ht {
    deny all;
  }

  location ~ /.well-known {
    allow all;
  }

  location = /robots.txt { log_not_found off; access_log off; allow all; }
  location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
    expires max;
    log_not_found off;
  }


  error_page 500 502 503 504 /50x.html;
  location = /50x.html {
    root /usr/share/nginx/html;
  }

  # Remove the annoying favicon request in logs
  location = /favicon.ico {
    return 204;
    access_log     off;
    log_not_found  off;
  }

  # Health check for Kubernetes readiness probe
  location /healthz {
    access_log off;
    return 200;
  }
}

However, navigating to http://localhost/blog immediately redirects me with a 302 and then a 404 to http://localhost/wp-admin/install.php.

If i do navigate to http://localhost/blog/wp-admin/install.php it shows the install page however, all the static content is missing with 404. They all point to http://localhost/wp-content e.t.c.

wordpress_1  | Jul 31 11:14:31 dbb622bd110b dbb622bd110b nginx: 192.168.32.1 - - [31/Jul/2018:11:14:31 +0200] "GET /blog/ HTTP/1.1" 302 5 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:61.0) Gecko/20100101 Firefox/61.0"
wordpress_1  | Jul 31 11:14:31 dbb622bd110b dbb622bd110b nginx: 192.168.32.1 - - [31/Jul/2018:11:14:31 +0200] "GET /wp-admin/install.php HTTP/1.1" 404 169 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:61.0) Gecko/20100101 Firefox/61.0"

Can someone please point me in the direction to get this right ? Not sure why the above Nginx configuration is wrong.

duanpao6163
duanpao6163 并不认为有必要在反向代理运行时更改它
大约 2 年之前 回复
dqwh1218
dqwh1218 toolong
大约 2 年之前 回复
duan7772
duan7772 博客是子目录,如内容所示。
大约 2 年之前 回复
doushaqing7080
doushaqing7080 首先,尝试删除索引声明周围的位置/块,其次我认为你不需要将博客附加到try_files上的位置/块,因为它将与页面的子目录一起使用,然后确保你有博客作为服务器上根结构中的子目录。
大约 2 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问