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 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥85 maple软件,solve求反函数,出现rootof怎么办?
    • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
    • ¥65 汇编语言除法溢出问题
    • ¥15 Visual Studio问题
    • ¥20 求一个html代码,有偿
    • ¥100 关于使用MATLAB中copularnd函数的问题