ubuntu如何配置nginx服务器

ubuntu如何配置nginx服务器?;来看看ubuntu 下的nginx服务器配置详解
1.nginx服务器的安装
sudo apt-get install nginx
2.nginx服务器的启动
sudo /etc/init.d/nginx start
3.多域名对应不同的后台服务器
【ubuntu如何配置nginx服务器】在/etc/nginx/sites-enabled/ 目录中删除default配置文件
新建域名对应的配置文件
比如test.youlunshidai.com
#通过upstream nodejs__upstream 可以配置多台nodejs节点,做负载均衡
upstream nodejs__upstream__test__youlunshidai {
server 127.0.0.1:8089; #服务器地址和端口号
#server 127.0.0.1:8088; #负载均衡服务器地址和端口号
keepalive 64; #设置存活时间 。如果不设置可能会产生大量的timewait
}
server {
listen 80;
server_name test.youlunshidai.com;
access_log /var/log/nginx/test_youlunshidai.log; #nginx日志文件
location / {
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;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_pass http://nodejs__upstream__test__youlunshidai; #反向代理转发 http://nodejs__upstream;
}
}
如果还有其他域名和后台服务器,在目录下继续新建对应的域名配置文件即可

ubuntu如何配置nginx服务器


    推荐阅读