1. 下载依赖
yum install -y curl
yum install -y openssl openssl-devel
yum install -y zlib zlib-devel
yum install -y pcre pcre-devel
yum install -y nginx
2. 启动 nginx
查询状态 service nginx status
启动nginx service nginx start
获取本地80端口返回 curl localhost:80
设置开机启动 systemctl enable nginx.service
3. 修改配置
vim /etc/nginx/nginx.conf
在 server 下添加配置 proxy_set_header 获取真实访问ip header
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
4. 测试
重载nginx service nginx start
外网访问 http://ip:80/
如果网络不可达需要检测云服务器的防火墙配置