doufen3838 2018-07-31 08:57
浏览 160

使用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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘