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

Analysis of nginx server configuration examples under ubuntu

王林
Release: 2023-05-22 08:16:38
forward
1013 people have browsed it

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;
 }
}
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template