nginx虚拟主机配置备忘

  1. 以下为nginx.conf,其中include /etc/nginx/conf.d/*.conf;为了方便管理,可以将server的定义包含在conf.d下,规划为每个conf文件负责一个server。
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.

events {
    worker_connections 1024;
}

http {
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
	include /etc/nginx/conf.d/*.conf;
	
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  www.example.com;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.

        location / {
	proxy_pass http://127.0.0.1:3032;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
  1. 以下为/etc/nginx/conf.d/目录下test.conf
server {
        listen       80;
        server_name  test.example.com;
        index  index.html index.htm;
        location / {
        	proxy_pass http://127.0.0.1:8001;
        }
}
  1. 同时,需要在域名供应商中,将www与test记录解析到此主机。

猜你喜欢

转载自blog.csdn.net/lik_lik/article/details/88964991