Home  >  Article  >  Operation and Maintenance  >  Analysis of nginx server configuration examples under ubuntu

Analysis of nginx server configuration examples under ubuntu

王林
王林forward
2023-05-22 08:16:38948browse

Detailed explanation of nginx server configuration under ubuntu

1.nginx server installation

sudo apt-get install nginx

2.nginx server Start

sudo /etc/init.d/nginx start

3. Multiple domain names correspond to different backend servers

In /etc/nginx/sites- Delete the default configuration file in the enabled/ directory

Create a configuration file corresponding to the domain name

For example, 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;
 }
}

If there are other domain names and backend server, continue to create the corresponding domain name configuration file in the directory

Analysis of nginx server configuration examples under ubuntu

#

The above is the detailed content of Analysis of nginx server configuration examples under ubuntu. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete