本文使用的是ubuntu 18.04系统,使用apt-get 方式安装nginx。
nginx的配置目录在/etc/nginx,目录中含如下文件:
1、nginx.conf文件
/etc/nginx/nginx.conf是nginx的核心配置文件,文件内容如下:
user www-data; worker_processes auto; #此数值越大,nginx并发能力越强 pid /run/nginx.pid; include /etc/nginx/modules-enabled/*.conf; events { worker_connections 768; #此数值越大,nginx的并发能力越强 # multi_accept on; } http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; #引入外部文件,存放媒体类型 default_type application/octet-stream; #默认使用的媒体类型 ## # SSL Settings ## ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE ssl_prefer_server_ciphers on; ## # Logging Settings ## access_log /var/log/nginx/access.log; #访问日志地址 error_log /var/log/nginx/error.log; #错误日志地址 ## # Gzip Settings ## gzip on; #开启gzip压缩 # gzip_vary on; # gzip_proxied any; # gzip_comp_level 6; # gzip_buffers 16 8k; # gzip_http_version 1.1; # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; #引入外部文件,配置server块(一般用于设置负载均衡) include /etc/nginx/sites-enabled/*; #引入外部文件,配置本机站点 } #mail { # # See sample authentication script at: # # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript # # # auth_http localhost/auth.php; # # pop3_capabilities "TOP" "USER"; # # imap_capabilities "IMAP4rev1" "UIDPLUS"; # # server { # listen localhost:110; # protocol pop3; # proxy on; # } # # server { # listen localhost:143; # protocol imap; # proxy on; # } #}
重点关注标红的两个目录。
2、/etc/nginx/sites-enable/default文件
此文件夹下只有一个文件default,使用ls -l命令查看:
default文件是 /etc/nginx/sites-available/default文件的链接。
因此,修改这两个文件的效果是相同的。
该default文件内容如下:
# Default server configuration # server { listen 80 default_server; #监听80端口 listen [::]:80 default_server; root /home/ubuntu/index/wwwroot; #站点物理路径 # Add index.php to the list if you are using PHP index index.html index.htm index.nginx-debian.html; server_name _; #站点名称 location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } } server { listen 8080; #监听8080端口 listen [::]:8080; server_name ddz; #站点名称 root /home/ubuntu/ddj/client/dist; #物理路径 index index.html; location / { try_files $uri $uri/ =404; } } server { listen 8090; #监听8090端口 listen [::]:8090; server_name chess; #站点名称 root /home/ubuntu/chess/dist; #物理路径 index index.html; location / { try_files $uri $uri/ = 404; } } server { listen 8088; #监听8088端口 listen [::]:8088; server_name eshop; #站点名称 root /home/ubuntu/eshop/dist; #物理路径 index index.html; location / { try_files $uri $uri/ = 404; } }
上述配置了80、8080、8090、8088共四个端口。
3、/etc/nginx/conf.d/目录下文件。
这个目录下默认为空,如果需要新建文件,应该以.conf为结尾。
这些文件用于反向代理和负载均衡的设置。具体设置方式见这篇文章。