nginx配置多站点

  1. whereis nginx 找到/etc/nginx目录,该目录是nginx在服务器上的配置目录。
  2. 找到默认的nginx.conf这是nginx的默认配置主文件。如果不确定可以ps aux|grep nginx查找nginxbin文件, 然后再执行 bin文件(一般就是/usr/sbin/nginx) -t 找到入口配置文件:
[root@izbp1hcv8qx068z2n4dzsfz sbin]# whereis nginx
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz
  1. http字段内配置include:
  1
  2 user  nginx;
  3 worker_processes  1;
  4
  5 error_log  /var/log/nginx/error.log warn;
  6 pid        /var/run/nginx.pid;
  7
  8
  9 events {
 10     worker_connections  1024;
 11 }
 12
 13
 14 http {
 15     include       /etc/nginx/mime.types;
 16     default_type  application/octet-stream;
 17
 18     log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
 19                       '$status $body_bytes_sent "$http_referer" '
 20                       '"$http_user_agent" "$http_x_forwarded_for"';
 21
 22     access_log  /var/log/nginx/access.log  main;
 23
 24     sendfile        on;
 25     #tcp_nopush     on;
 26
 27     keepalive_timeout  65;
 28
 29     gzip  on;
 30
 31     include /etc/nginx/conf.d/*.conf;  // 代表该目录下所有的conf结尾      
        的配置文件都会一并执行
 32 }
  1. 然后在子配置文件进行配置即可,例如:
# 配置photo.api.qiansimin.xyz该域名的80端口代理到http://127.0.0.1:3721此服务上去
server {
        listen 80;
        server_name photo.api.qiansimin.xyz;
        location / {
                proxy_pass http://127.0.0.1:3721;
        }
}

你可能感兴趣的:(nginx配置多站点)