Nginx支持直接开启basic auth,开启Basic_Auth登录后客户端需要在请求头部添加Basic_Auth的内容方可继续访问 在nginx配置文件的server段添加以下 server { #…… auth_basic “XXXX”; #提示登录文本 auth_basic_user_file conf/htpasswd; #密码文件路径 #…… } 两种方式生成basic auth的密码 使用openssl printf “username:$(openssl passwd -crypt 123456)\n” >>conf/htpasswd 使用htpasswd #创建 htpasswd -c -d conf/htpasswd username #修改 htpasswd -b -d conf/htpasswd username passwd
Tag Archives: nginx
nginx 首页不存在时默认返回404而不是403
nginx 首页不存在时默认返回404而不是403 域名被某站劫持了导致整站被B,通过nginx设置将指定域名bound到指定的站点,然后强制返回404。 location = / { return 404; } 但是首页还是返回403代码。而不是预期的404。 于是让404正常,再直接把首页301 到一个不存在的资源。 完工 location = / { index index.html return 404; } location = /index.html { return 301 /noexsit; }
[WordPress] 子目录下WP建站Nginx反向代理设置
子目录下WP建站Nginx反向代理设置 参考官方文档,两种方式一下都可以实现要求 方法1,rewrite方式,适用php-fpm location /替换子目录名称/ { index index.html index.php; if (-f $request_filename/index.html){ rewrite (.*) $1/index.html break; } if (-f $request_filename/index.php){ rewrite (.*) $1/index.php; } if (!-f $request_filename){ rewrite (.*) /替换子目录名称/index.php; } } 方法2,使用try_files方式 location /替换子目录名称/ { index index.php; try_files $uri $uri/ /替换子目录名称/index.php?$args; } 必须要做的,把wp-admin单独处理 rewrite /替换子目录名称/wp-admin$ $scheme://$host$uri/ permanent;
Nginx HTTP站点使用301跳转HTTPS
方法一,使用Return方式,适用于全站HTTPS server_name www.lidaren.com lidaren.com; return 301 https://www.lidaren.com$request_uri; 方法二,rewirte方式转发特定目录,适用于子目录HTTPS化 location 使用 ·/· 根目录则全站跳转 location 使用 ·/XXX目录· 子目录则跳转指定子目录 location / { rewrite ^(.*) https://www.lidaren.com$1 permanent } 完整参考 server { listen 80; server_name www.lidaren.com lidaren.com; # 方法一,使用Return方式,适用于全站HTTPS return 301 https://www.lidaren.com$request_uri; # 方法二,rewirte方式转发特定目录,适用于子目录HTTPS化 # location 使用/根目录则全站跳转 # location / { # rewrite ^(.*) https://www.lidaren.com$1 permanent # } }
CentOS6.x/7.x配置Nginx系统服务
使用源代码编译方式安装Nginx的时候,肯定不如用用yum方式安装来得便捷,CentOS的系统服务需要自行配置。 自行配置Nginx为CentOS的系统服务时,出于进程管理考虑需要首先配置pid,出于安全考虑建议修改nginx的运行用户。 创建nginx.pid文件用于nginx主进程 touch /usr/local/nginx/logs/nginx.pid 修改conf/nginx.conf,设置pid和user user nobody; pid logs/nginx.pid; CentOS6.x配置nginx系统服务 创建一个/etc/init.d/nginx文件 touch /etc/init.d/nginx chmod 755 /etc/init.d/nginx /etc/init.d/nginx文件中写入以下内容, 源文件取自yum方式安装后的文件,不过需要自己修改一下nginx的指向位置 nginx=”/usr/local/nginx/sbin/nginx” NGINX_CONF_FILE=”/usr/local/nginx/conf/nginx.conf”
[CentOS] JDK+tomcat集群+nginx一键安装脚本
[CentOS] JDK+tomcat集群+nginx一键安装脚本 整理了一下在CentOS下JDK+tomcat集群+nginx的安装脚本. 支持CentOS6.x/7.x 1.安装前准备 # is root user if [ “$(whoami)” != ‘root’ ]; then echo “install need root user” exit fi
nginx对wordpress的sitemap插件生成的URL进行rewrite
WordPress 默认使用apache的URL改写,一般修改.htaccess文件即可。如果使用nginx+php-fpm模式的服务器,需要自己进行重写URL。 nginx+php-fpm模式下,Yoast SEO和Google Sitemap Generator两款Sitemap插件可以使用一下配置实现Nginx对SitemapURL的重写。