回到顶部

CONTENTS

nginx 同一 iP 多域名配置方法(多文件)

一、Nginx 配置文件

  路径:/usr/local/nginx/conf/nginx.conf

  操作:在 http 模块增加(子配置文件的路径和名称):include vhost/*.conf;  另外需要注意一下 user 后面要改成 root.

user root;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    #子配置文件的目录和文件后缀
    include vhost/*.conf;


    
}

二、Nginx 子配置文件

  路径:/usr/local/nginx/conf/vhost

[root@VM_2_29_centos vhost]# ls
xieboke.net.conf  zhuoqun.info.conf

  子配置文件例子:[root@VM_2_29_centos vhost]# vim xieboke.net.conf 

server {
        listen       80;
        listen       443;
        server_name  xieboke.net;
        charset utf-8;

        ssl on;
        ssl_certificate      /root/yzq/ssl/xieboke.net/1_xieboke.net_bundle.crt;
        ssl_certificate_key  /root/yzq/ssl/xieboke.net/2_xieboke.net.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        access_log  /root/yzq/logs/xieboke.net.access.log;
        error_log   /root/yzq/logs/xieboke.net.error.log;

        location / {
                  # 监听 9090 端口,与 ini 里的 socket 设置成同一个端口
                  uwsgi_pass 127.0.0.1:9090;
                  include uwsgi_params;
                  # root   html;
                  # index  index.html index.htm;
                }

        location /media {
                  alias /root/yzq/djangos/blog/media;
                }

        location /static {
                  alias /root/yzq/djangos/blog/static_root;
                  # proxy_pass http://static.xieboke.net/static_root;
                  # rewrite /static/(.*) http://static.xieboke.net/static_root/$1;
                }
       }
   

三、检查 nginx 配置

       命令:nginx -t

[root@VM_2_29_centos log]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

四、启动 nginx ( 指定配置文件 )

      命令:/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

五、重载 nginx

      命令: nginx -s reload

六、注意

      如果编译时,没选择 ssl 模块,后续添加 ssl 就需要重新编译和安装。./configure --prefix=/usr/local/nginx-1.14.2 --with-http_ssl_module -> make&&make install.

^_^
请喝咖啡 ×

前一篇: 测试工程师 - 要了解的技能总结
下一篇: HttpRunnerManager 接口自动化测试平台 搭建实践