Posted on 六月 14, 2018
CentOS7安装Nginx及二级域名转发
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm 安装 sudo yum install -y nginx 设置开机运行 sudo systemctl enable nginx.service 启动 sudo systemctl start nginx.service 重启 nginx -s reload 编辑配置文件 vim /etc/nginx/nginx.conf
在域名服务商设置二级域名解析,解析到服务器ip。服务器80出口是Nginx,Nginx配置二级域名转发。
server { listen 80; server_name *.truestudio.tech; if ($http_host ~* "^(.*?)\.truestudio\.tech$") { set $domain $1; } location / { if ($domain ~* "zhuqiaochu") { proxy_pass http://localhost:81; } if ($domain ~* "www") { proxy_pass http://localhost:82; } tcp_nodelay on; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; root html; index index.html index.htm; } }
参考:
https://www.cnblogs.com/songxingzhu/p/8568432.html
https://www.jb51.net/article/113997.htm
https://blog.csdn.net/Metropolis_cn/article/details/73613022?locationNum=7&fps=1