Nginx配置多个访问路径

Nginx配置多个service 多个访问路径

找到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 {
    client_max_body_size 20M;
    client_body_buffer_size 10M;
    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;

    server {
	listen       80;
	server_name localhost;
	ssi on;

	ssi_silent_errors on;
	
    ssi_types text/html;
	location / {
	   proxy_ignore_client_abort on;
	    root   F:/Tengxun/code20191104/brmall-manage-web;
	    index  index.html;
	}
	location ^~ /api/ {	
	    proxy_ignore_client_abort on;
	    proxy_http_version 1.1; 
  
	    proxy_pass http://127.0.0.1:8080;
	    proxy_cookie_path / /;
	    proxy_pass_header Set-Cookie;
	    proxy_set_header Connection '';
	    proxy_buffering off;
	    proxy_cache off;
	    chunked_transfer_encoding off;
	    proxy_set_header Host $http_host;
	    proxy_set_header X-Real-IP $remote_addr;
	    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	    proxy_set_header X-Forwarded-Proto $scheme;
	}
	 location /file{
   		 alias D:/imgs/;#指定图片的路径
   		 autoindex on;
   	 }
    }

	server {
	listen       81;
	server_name localhost;
	ssi on;
	ssi_silent_errors on;
	ssi_types text/html;
		location / {
		   proxy_ignore_client_abort on;
		    root   F:/Tengxun/code20191104/brmall-user-center-web;
		    index  html/user/reg.html;
		}
		location ^~ /api/ {	
		    proxy_ignore_client_abort on;
		    proxy_http_version 1.1; 
	  
		    proxy_pass http://127.0.0.1:8081;
		    proxy_cookie_path / /;
		    proxy_pass_header Set-Cookie;
		    proxy_set_header Connection '';
		    proxy_buffering off;
		    proxy_cache off;
		    chunked_transfer_encoding off;
		    proxy_set_header Host $http_host;
		    proxy_set_header X-Real-IP $remote_addr;
		    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		    proxy_set_header X-Forwarded-Proto $scheme;
		}
       }

	server {
	listen       82;
	server_name localhost;
	ssi on;
	ssi_silent_errors on;
	ssi_types text/html;
		location / {
		   proxy_ignore_client_abort on;
		    root   F:/Tengxun/_user_center_web/web;
		    index  index.html;
		}
		location ^~ /api/ {	
		    proxy_ignore_client_abort on;
		    proxy_http_version 1.1; 
	  
		    proxy_pass http://127.0.0.1:8082;
		    proxy_cookie_path / /;
		    proxy_pass_header Set-Cookie;
		    proxy_set_header Connection '';
		    proxy_buffering off;
		    proxy_cache off;
		    chunked_transfer_encoding off;
		    proxy_set_header Host $http_host;
		    proxy_set_header X-Real-IP $remote_addr;
		    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		    proxy_set_header X-Forwarded-Proto $scheme;
		}
       }

       server {
	listen       83;
	server_name localhost;
	ssi on;
	ssi_silent_errors on;
	ssi_types text/html;
		location / {
		   proxy_ignore_client_abort on;
		    root   F:/Tengxun/_manage/-manage-web;
		    index  index.html;
		}
		location ^~ /api/ {	
		    proxy_ignore_client_abort on;
		    proxy_http_version 1.1; 
	  
		    proxy_pass http://127.0.0.1:8080;
		    proxy_cookie_path / /;
		    proxy_pass_header Set-Cookie;
		    proxy_set_header Connection '';
		    proxy_buffering off;
		    proxy_cache off;
		    chunked_transfer_encoding off;
		    proxy_set_header Host $http_host;
		    proxy_set_header X-Real-IP $remote_addr;
		    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		    proxy_set_header X-Forwarded-Proto $scheme;
		}
       }
    
     server {
	listen       84;
	server_name localhost;
	ssi on;
	ssi_silent_errors on;
	ssi_types text/html;
		location / {
		   proxy_ignore_client_abort on;
		    root   F:/Tengxun/_ps_manage/-ps-manage-web;
		    index  index.html;
		}
		location ^~ /api/ {	
		    proxy_ignore_client_abort on;
		    proxy_http_version 1.1; 
	  
		    proxy_pass http://127.0.0.1:8080;
		    proxy_cookie_path / /;
		    proxy_pass_header Set-Cookie;
		    proxy_set_header Connection '';
		    proxy_buffering off;
		    proxy_cache off;
		    chunked_transfer_encoding off;
		    proxy_set_header Host $http_host;
		    proxy_set_header X-Real-IP $remote_addr;
		    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		    proxy_set_header X-Forwarded-Proto $scheme;
		}
       }

		


    # another virtual host using mix of IP-, name-, and port-based configuration
    #


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

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

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

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

参数说明

  • 修改 server 里面的 一些参数即可
  • listen :端口
  • server_name :访问地址
  • root :项目路劲
  • index :启动访问首页

如果你想要多个路径多配置 个 server 即可

server {
	listen       80;
	server_name localhost;
	ssi on;

	ssi_silent_errors on;
	
    ssi_types text/html;
	location / {
	   proxy_ignore_client_abort on;
	    root   F:/Tengxun/code20191104/brmall-manage-web;
	    index  index.html;
	}
	location ^~ /api/ {	
	    proxy_ignore_client_abort on;
	    proxy_http_version 1.1; 
  
	    proxy_pass http://127.0.0.1:8080;
	    proxy_cookie_path / /;
	    proxy_pass_header Set-Cookie;
	    proxy_set_header Connection '';
	    proxy_buffering off;
	    proxy_cache off;
	    chunked_transfer_encoding off;
	    proxy_set_header Host $http_host;
	    proxy_set_header X-Real-IP $remote_addr;
	    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	    proxy_set_header X-Forwarded-Proto $scheme;
	}
	 location /file{
   		 alias D:/imgs/;#指定图片的路径
   		 autoindex on;
   	 }
    }

重新启动nginx、或者重新reload一下

start nginx 启动
nginx -s reload  刷新
nginx -s stop

你可能感兴趣的:(Nginx配置多个访问路径)