码迷,mamicode.com
首页 > Windows程序 > 详细

nginx配置一、二级域名、多域名对应(api接口、前端网站、后台管理网站)

时间:2017-07-12 20:01:23      阅读:820      评论:0      收藏:0      [点我收藏+]

标签:http   配置   bre   erer   sse   request   timeout   nbsp   param   

前提:安装好nginx,如果已经启动nginx,先停止,命令:

./usr/local/nginx/sbin/nginx -s stop

修改nginx配置

vi /usr/local/nginx/conf/nginx.conf  

配置好以后的nginx.conf文件内容:

#user  nobody;
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;

    upstream  tomcat8080_api {  
        server 127.0.0.1:8080  weight=1;
    }
    server {
        listen       80;
        server_name  后台接口域名;
        location / {
            proxy_pass http://tomcat8080_api;  
            proxy_redirect default;      
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    
    upstream  tomcat8081_admin {  
        server 127.0.0.1:8081  weight=1;  
    }
    server {
        listen       80;
        server_name  管理员后台域名;
        location / {
            proxy_pass http://tomcat8081_admin;  
            proxy_redirect default;
        }
        #解决跨域
        location /apis  {                                # 自定义nginx接口前缀
            rewrite  ^/apis/(.*)$ /$1 break;            # 监听所有/apis前缀,是则转发后台api接口地址
            include  uwsgi_params;
            proxy_pass   http://127.0.0.1:8080;            # 后台api接口地址
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    server {
        listen       80;
        server_name  管理员后台域名2;
        location / {
            proxy_pass http://tomcat8081_admin;  
            proxy_redirect default;
        }
        #解决跨域
        location /apis  {                                # 自定义nginx接口前缀
            rewrite  ^/apis/(.*)$ /$1 break;            # 监听所有/apis前缀,是则转发后台api接口地址
            include  uwsgi_params;
            proxy_pass   http://127.0.0.1:8080;            # 后台api接口地址
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    server {
        listen       80;
        server_name  管理员后台域名3;
        location / {
            proxy_pass http://tomcat8081_admin;  
            proxy_redirect default;
        }
        #解决跨域
        location /apis  {                                # 自定义nginx接口前缀
            rewrite  ^/apis/(.*)$ /$1 break;            # 监听所有/apis前缀,是则转发后台api接口地址
            include  uwsgi_params;
            proxy_pass   http://127.0.0.1:8080;            # 后台api接口地址
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    
    upstream  tomcat8082_shanghu {  
        server 127.0.0.1:8082  weight=1;
    }
    server {
        listen       80;
        server_name  商家后台域名;
        location / {
            proxy_pass http://tomcat8082_shanghu;
            proxy_redirect default;
        }
        #解决跨域
        location /apis  {                                # 自定义nginx接口前缀
            rewrite  ^/apis/(.*)$ /$1 break;            # 监听所有/apis前缀,是则转发后台api接口地址
            include  uwsgi_params;
            proxy_pass   http://127.0.0.1:8080;            # 后台api接口地址
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

 

启动nginx命令:

./usr/local/nginx/sbin/nginx

重启nginx命令:

./usr/local/nginx/sbin/nginx -s reload

 

nginx配置一、二级域名、多域名对应(api接口、前端网站、后台管理网站)

标签:http   配置   bre   erer   sse   request   timeout   nbsp   param   

原文地址:http://www.cnblogs.com/007sx/p/7156922.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!