标签归档:nginx

nginx: [emerg] unknown directive “proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for” in

nginx配置代理转发,部分配置如下

        location / {
            # index index.html index.htm index.php;
            # try_files $uri $uri/ /index.php$request_uri;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Real-Port $remote_port;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass https://10.29.185.61:8063;
        }

reload nginx,正常,配置和header生效
restart nginx,重启失败。。。。

运行nginx,返回:
nginx: [emerg] unknown directive “proxy_set_header X-Real-IP $remote_addr” in /etc/nginx/doufu.la.conf:54
注释掉
# proxy_set_header X-Real-IP $remote_addr;
运行nginx,返回:
nginx: [emerg] unknown directive “proxy_set_header X-Real-Port $remote_port” in /etc/nginx/doufu.la.conf:55
注释掉
# proxy_set_header X-Real-Port $remote_port;
运行nginx,返回:
nginx: [emerg] unknown directive “proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for” in /etc/nginx/doufu.la.conf:56
注释掉
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

MMP,咋回事啊?
nginx -t啊,先test,论test的重要性

正确:
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

结论:
不要随便copy代码

Nginx Yum安装(官方)

To set up the yum repository, create the file named /etc/yum.repos.d/nginx.repo with the following contents:

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key