nginx 配置 同一個域名 同時支援iis和tomcat
參考如下:
http://127.0.0.1:8888 預設就是那個域名指向的網站 比如說localhost. 對應的我弄在了tomcat中,配置context上下文 空預設就是對應的這個應用網站 homeweb (這裡只是個名字,具體網站的資料夾名是在tomcat中配置的<Context path="" docBase="d:/xxx/xxx" reloadable="true "/> 通過 http://127.0.0.1:8888 可以訪問
另外tomcat 8888埠下 還有另外一個應用網站 xxxx-guanwang-file 通過http://127.0.0.1:8888/xxxx-guanwang-file 也可以訪問
iis 是改為了81埠 下面有一個網站test1 通過http://127.0.0.1:81/test1 可以訪問
配置上nginx後,通過 http://localhost/ 可以訪問預設tomcat下8888預設的網站。 通過http://localhost/xxxx-guanwang-file 可以訪問tomcat下的xxxx-guanwang-file 。通過http://localhost/test1 可以訪問iis下的test1網站。具體配置如下
#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 homeweb{
server 127.0.0.1:8888;
}
upstream guanwangfile{
server 127.0.0.1:8888;
}
upstream iistest{
server 127.0.0.1:81;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://homeweb;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#允許客戶端請求的最大的單個檔案位元組數
client_max_body_size 1024m;
#緩衝區代理緩衝使用者端請求的最大位元組數 可以理解為先儲存到本地再傳給使用者
client_body_buffer_size 128k;
#跟後端伺服器連線的超時時間_發起握手等候響應超時時間
proxy_connect_timeout 300;
#連線成功後_等候後端伺服器響應時間_其實已經進入後端的排隊之中等候處理
proxy_read_timeout 300;
#後端伺服器資料回傳時間_就是在規定時間之內後端伺服器必須傳完所有的資料
proxy_send_timeout 300;
#代理請求快取區_這個快取區間會儲存使用者的頭資訊以供Nginx進行規則處理_一般只要能儲存下頭資訊即可
proxy_buffer_size 4k;
#同上 告訴Nginx儲存單個用的幾個Buffer 最大用多大空間
proxy_buffers 4 32k;
#如果系統很忙的時候可以申請更大的proxy_buffers 官方推薦*2
proxy_busy_buffers_size 64k;
#proxy快取臨時檔案的大小
proxy_temp_file_write_size 64k;
}
location ^~ /xxxx-guanwang-file {
proxy_pass http://guanwangfile;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#允許客戶端請求的最大的單個檔案位元組數
client_max_body_size 1024m;
#緩衝區代理緩衝使用者端請求的最大位元組數 可以理解為先儲存到本地再傳給使用者
client_body_buffer_size 128k;
#跟後端伺服器連線的超時時間_發起握手等候響應超時時間
proxy_connect_timeout 300;
#連線成功後_等候後端伺服器響應時間_其實已經進入後端的排隊之中等候處理
proxy_read_timeout 300;
#後端伺服器資料回傳時間_就是在規定時間之內後端伺服器必須傳完所有的資料
proxy_send_timeout 300;
#代理請求快取區_這個快取區間會儲存使用者的頭資訊以供Nginx進行規則處理_一般只要能儲存下頭資訊即可
proxy_buffer_size 4k;
#同上 告訴Nginx儲存單個用的幾個Buffer 最大用多大空間
proxy_buffers 4 32k;
#如果系統很忙的時候可以申請更大的proxy_buffers 官方推薦*2
proxy_busy_buffers_size 64k;
#proxy快取臨時檔案的大小
proxy_temp_file_write_size 64k;
}
location ^~ /test1 {
proxy_pass http://iistest;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#允許客戶端請求的最大的單個檔案位元組數
client_max_body_size 1024m;
#緩衝區代理緩衝使用者端請求的最大位元組數 可以理解為先儲存到本地再傳給使用者
client_body_buffer_size 128k;
#跟後端伺服器連線的超時時間_發起握手等候響應超時時間
proxy_connect_timeout 300;
#連線成功後_等候後端伺服器響應時間_其實已經進入後端的排隊之中等候處理
proxy_read_timeout 300;
#後端伺服器資料回傳時間_就是在規定時間之內後端伺服器必須傳完所有的資料
proxy_send_timeout 300;
#代理請求快取區_這個快取區間會儲存使用者的頭資訊以供Nginx進行規則處理_一般只要能儲存下頭資訊即可
proxy_buffer_size 4k;
#同上 告訴Nginx儲存單個用的幾個Buffer 最大用多大空間
proxy_buffers 4 32k;
#如果系統很忙的時候可以申請更大的proxy_buffers 官方推薦*2
proxy_busy_buffers_size 64k;
#proxy快取臨時檔案的大小
proxy_temp_file_write_size 64k;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
server{
listen 80;
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# 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;
# }
#}
}