7篇 nginx related articles

nginx隐藏错误页的版本号

The “server_tokens” directive is responsible for displaying the Nginx version number and Operating system on error pages and in the “Server” HTTP response header field as shown in the following screenshot.

To disable this, you need to turn off the server_tokens directive in /etc/nginx/nginx.conf configuration file.

vi /etc/nginx/nginx.conf

More ~

K8S实战(二)| 发布容器到 K8S 集群中

容器来源

使用 nginx 的官方容器镜像。

发布容器的两种方式

镜像有了,我们如何将其提交给 K8S 运行呢,有两种方式:

  1. 命令行方式(不推荐)。
  2. 配置文件方式(推荐)。

这里使用官方推荐的第二种方式,即通过将容器的各种信息写入配置文件提交给 K8S。

More ~

nginx配置重定向 HTTP到HTTPS

Redirect All HTTP

server {
    listen 80 default_server;

    server_name _;

    return 301 https://$host$request_uri;
}

Redirect Specific Sites

server {
    listen 80;

    server_name foo.com;
    return 301 https://foo.com$request_uri;
}
More ~

nginx: [warn] the "ssl" directive is deprecated

当执行 nginx -s reload 时报出:

nginx: [warn] the "ssl" directive is deprecated, use the "listen ... ssl" directive instead in /etc/nginx/conf.d/xxx.conf:29

原来可能这样写:

server {
    listen       443 ssl;
    server_name  www.zixi.org;
    ssl on;
    ...

现在直接去掉ssl on; 这一行即可。

More ~

CentOS7 firewall防火墙允许nginx http https被访问

##添加允许通过服务
查看所有服务 firewall-cmd --get-services

firewall-cmd --add-service=http

firewall-cmd --add-service=https

##参考:

打开443/TCP端口

firewall-cmd --add-port=443/tcp

永久打开3690/TCP端口

firewall-cmd --permanent --add-port=3690/tcp

更新后重新加载

firewall-cmd --reload

查看防火墙,添加的端口也可以看到

firewall-cmd --list-all

More ~

centos7 nginx php 访问本地redis报权限问题

事情是这样:nginx 反向代理 php-fpm, php脚本中使用php-redis,实例化Redis对象,并connect本地的redis服务器。本地root账号运行php xxx.php是没有问题的,结果使用http访问时报Permission denied。
如果不提示错误,有可能是php.ini的配置项display_errors是关闭的。

最终找到原因是selinux的安全设置。可以用这个getsebool -a | grep httpd 查看到
httpd_can_network_connect --> off

可以通过下述命令修改
SELinux命令,临时配置,重启后失效
setsebool httpd_can_network_connect=1

写入配置文件的命令,重启后保留
setsebool -P httpd_can_network_connect 1

其它配置项参考 https://wiki.centos.org/zh/TipsAndTricks/SelinuxBooleans

More ~