全球主机交流论坛

标题: 请教,nginx如果要密码保护wp-admiin目录,该怎么写nginx.conf [打印本页]

作者: HXS    时间: 2016-6-14 00:18
标题: 请教,nginx如果要密码保护wp-admiin目录,该怎么写nginx.conf
总是搞不定,
nginx的密码保护目录挺复杂的啊
求提供nginx.conf文件


作者: HXS    时间: 2016-6-18 11:12
tt
作者: 蓝翔技校    时间: 2016-6-18 11:21
搭车同求。
作者: _jerryjee    时间: 2016-6-18 14:43
同求~
作者: mix    时间: 2016-6-18 16:13
是不是可以这样,修改wp-admin目录下的index,index加密然后重定向到
作者: 今晚我是你的    时间: 2016-6-18 18:36
5楼说的比较对
作者: funders    时间: 2016-6-18 21:54
自己用htpasswd生成用户名 密码,没装的话到http://tool.oschina.net/htpasswd  加密算法选 MD5 apache

然后加密的hash保存到 /xxxx/xxxx/xx.com.htpasswd

nginx的vhost文件里,我这个是军哥lnmp的配置文件,自己添加

  1.          location /wp-admin/ {
  2.                 auth_basic "login:";
  3.                 auth_basic_user_file /xxxx/xxxx/xx.com.htpasswd;
  4.          }

  5. 这个上面的就是密码验证
  6.         location ~ [^/]\.php(/|$)
  7.         {
  8.             # comment try_files $uri =404; to enable pathinfo
  9.             try_files $uri =404;
  10.             fastcgi_pass  unix:/tmp/php-cgi.sock;
  11.             fastcgi_index index.php;
  12.             include fastcgi.conf;
  13.             #include pathinfo.conf;
  14.         }
复制代码

作者: HXS    时间: 2016-6-18 22:10
funders 发表于 2016-6-18 21:54
自己用htpasswd生成用户名 密码,没装的话到http://tool.oschina.net/htpasswd  加密算法选 MD5 apache

然 ...

大哥,nginx的密码保护目录默认不运行php的,这样可行吗?
作者: funders    时间: 2016-6-18 22:13
HXS 发表于 2016-6-18 22:10
大哥,nginx的密码保护目录默认不运行php的,这样可行吗?

怎么可能  我就这样保护我的wp后台的啊,不能执行php我怎么登录呢
作者: HXS    时间: 2016-6-18 22:14
funders 发表于 2016-6-18 22:13
怎么可能  我就这样保护我的wp后台的啊,不能执行php我怎么登录呢

那我也试试,我以为这样不行的
作者: HXS    时间: 2016-6-18 22:32
funders 发表于 2016-6-18 22:13
怎么可能  我就这样保护我的wp后台的啊,不能执行php我怎么登录呢

不行,我加了之后404
作者: funders    时间: 2016-6-18 22:38
HXS 发表于 2016-6-18 22:32
不行,我加了之后404
  1. server {
  2.     listen       80;
  3.     server_name www.xxxxxxx.com xxxxxxx.com;
  4.     return 301 https://$host$request_uri;
  5. }

  6. server
  7.     {
  8.         listen 443;
  9.         #listen [::]:80;
  10.         server_name www.xxxxxxx.com xxxxxxx.com;
  11.         index index.html index.htm index.php default.html default.htm default.php;
  12.         root  /data/www/xxxxxxx.com;

  13.         ssl on;
  14. #    ssl_certificate /etc/nginx/ssl/xxxxxxx.com_bundle.crt;
  15. #    ssl_certificate_key /etc/nginx/ssl/xxxxxxx.com.key;

  16.         ssl_certificate /data/ssl.xxxxxxx/xxxxxxx.com.crt;
  17.         ssl_certificate_key /data/ssl.xxxxxxx/xxxxxxx.com.key;

  18.         ssl_session_timeout 5m;
  19.         ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

  20.         ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:DHE-RSA-AES128-GCM-SHA256:AES256+EDH:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";

  21.         ssl_prefer_server_ciphers on;
  22.         ssl_session_cache shared:SSL:10m;
  23.         ssl_dhparam /etc/ssl/certs/dhparam.pem;

  24.         include wordpress.conf;
  25.         #error_page   404   /404.html;


  26.          location /wp-admin/ {
  27.                 auth_basic "login:";
  28.                 auth_basic_user_file /data/www/xxxxxx.com.passwd;
  29.          }


  30.         location ~ [^/]\.php(/|$)
  31.         {
  32.             # comment try_files $uri =404; to enable pathinfo
  33.             try_files $uri =404;
  34.             fastcgi_pass  unix:/tmp/php-cgi.sock;
  35.             fastcgi_index index.php;
  36.             include fastcgi.conf;
  37.             #include pathinfo.conf;
  38.         }

  39.         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  40.         {
  41.             expires      30d;
  42.         }

  43.         location ~ .*\.(js|css)?$
  44.         {
  45.             expires      12h;
  46.         }

  47.         access_log  /data/logs/xxxxxxx.com.access.log access;
  48.     }
复制代码


我的站配置。lnmp1.2 /usr/local/nginx/conf/vhost/xxxxx.com.conf
自己对应修改看看
作者: funders    时间: 2016-6-18 22:42
funders 发表于 2016-6-18 22:38
我的站配置。lnmp1.2 /usr/local/nginx/conf/vhost/xxxxx.com.conf
自己对应修改看看

404的问题估计是
        location ~ [^/]\.php(/|$)
        {
            # comment try_files $uri =404; to enable pathinfo
            try_files $uri =404;
            fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_index index.php;
            include fastcgi.conf;
            #include pathinfo.conf;
        }

这段问题,yum apt安装的lnmp不能这样写的。你得先测试能解析php,再添加那个密码验证字段看看
作者: HXS    时间: 2016-6-18 22:44
funders 发表于 2016-6-18 22:42
404的问题估计是
        location ~ [^/]\.php(/|$)
        {

这段我没有复制你的,我按照php-fpm的默认设置来的
作者: HXS    时间: 2016-6-18 22:45
难道跟我的开启的WP伪静态有关系??
作者: HXS    时间: 2016-6-19 20:24
继续求一下
作者: Annual    时间: 2016-6-19 22:14
现在CDN不是有指定目录白名单IP么?做个跳板不是很好么




欢迎光临 全球主机交流论坛 (https://sunk.eu.org/) Powered by Discuz! X3.4