Windows下 配置Nginx+Tomcat

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weifeifei213/article/details/79955712

1.下载Nginx并解压到一个目录下,例如:D:\ApacheSoftware\Nginx

2.修改配置文件conf/nginx.conf,

在http {}中的最后面加上include vhost/*.conf;

http{   
#其他配置
include vhost/*.conf;
}

3.在conf目录下新建 vhost目录,在vhost目录下面新建  文件名.conf的文件,文件名自定义,一般采用域名对其进行命名。

配置内容如下:

upstream  192.168.0.102{
server  192.168.0.102:8081;
}

server {
	listen 8080;
	server_name 192.168.0.102;
	access_log  logs/pandora_sale_access.log;
	error_log   logs/pandora_sale_error.log;
	#root D:\ApacheSoftware\Nginx\nginx-1.13.8\html\host1;
	location / {
		client_max_body_size  0;
		gzip  off;
		proxy_pass http://192.168.0.102;
		proxy_set_header  X-Real-IP $remote_addr;
		proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header  Host $http_host;

	}
}

其中server  192.168.0.102:8081是Tomcat的访问路径

upstream和proxy_pass后的IP地址保持一致,server_name 为访问域名,可以配置为IP地址

最后重启Nginx就可以了

nginx -s reload

阅读更多

[请教]windowsnginx+tomcat配置

05-02

我在 windows Xp下配置了nginx1.1+tomcat6.0 rnrn我用的2个tomcat做测试端口分别设定为监听:8088和8089。shutdown:8005和8006rnrn配置完成以后我打开浏览器访问rnrn但是很慢很慢 不知道哪有问题 直接访问tomcat的默认猫页面都很慢很慢rnrn我怀疑是nginx的分发问题,但是怎么修改配置文件都没有用rnrn我是本地直接访问本地 不经过互联网,应该也不存在网速问题吧?rnrn以下是nginx配置文件的信息rnrn求指教!rnrnrnrn#user www www;rnworker_processes 2;rnrn#error_log logs/error.log;rn#error_log logs/error.log notice;rn#error_log logs/error.log info;rnrn#pid logs/nginx.pid;rnrnrnevents rn worker_connections 1024;rnrnrnrnhttp rn include mime.types;rn default_type application/octet-stream;rnrn #设定请求缓冲 rn server_names_hash_bucket_size 128; rn client_header_buffer_size 32k; rn large_client_header_buffers 4 32k; rn client_max_body_size 300m; rn sendfile on; rn tcp_nopush on; rn keepalive_timeout 60; rn tcp_nodelay on; rn server_tokens off;rn client_body_buffer_size 512k; rn proxy_connect_timeout 5; rn proxy_send_timeout 60; rn proxy_read_timeout 5; rn proxy_buffer_size 16k; rn proxy_buffers 4 64k; rn proxy_busy_buffers_size 128k; rn proxy_temp_file_write_size 128k; rn # fastcgi_connect_timeout 300; rn # fastcgi_send_timeout 300; rn # fastcgi_read_timeout 300; rn # fastcgi_buffer_size 64k; rn # fastcgi_buffers 4 64k; rn # fastcgi_busy_buffers_size 128k; rn # fastcgi_temp_file_write_size 128k; rn gzip on; rn gzip_min_length 1k; rn gzip_buffers 4 16k; rn gzip_http_version 1.1; rn gzip_comp_level 2; rn gzip_types text/plain application/x-javascript text/css application/xml; rn gzip_vary on; rn rn #limit_zone crawler $binary_remote_addr 10m;rnrnrn upstream backend rn server localhost:8089 weight=1;rn server localhost:8088 weight=2;rn rnrn server rn listen 800;rn server_name localhost;rn rn #charset koi8-r;rnrn #access_log logs/host.access.log main;rnrnrnlocation ~ \.(jsp|page|do)?$ rn proxy_set_header Host $host; rn proxy_set_header X-Real-IP $remote_addr;rn proxy_pass http://backend;#转向tomcat处理 rn rnrnrnlocation ~ .*\.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$ #设定访问静态文件直接读取不经过tomcat rn rn expires 30d; rn rn location ~ .*\.(js|css)?$ rn rn expires 1h; rn rnrnrnrn rn #error_page 404 /404.html;rnrn # redirect server error pages to the static page /50x.htmlrn #rn error_page 500 502 503 504 /50x.html;rn location = /50x.html rn root html;rn rnrn # proxy the PHP scripts to Apache listening on 127.0.0.1:80rn #rn #location ~ \.php$ rn # proxy_pass http://127.0.0.1;rn #rnrn # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000rn #rn #location ~ \.php$ rn # root html;rn # fastcgi_pass 127.0.0.1:9000;rn # fastcgi_index index.php;rn # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;rn # include fastcgi_params;rn #rnrn # deny access to .htaccess files, if Apache's document rootrn # concurs with nginx's onern #rn #location ~ /\.ht rn # deny all;rn #rn rnrnrn # another virtual host using mix of IP-, name-, and port-based configurationrn #rn #server rn # listen 8000;rn # listen somename:8080;rn # server_name somename alias another.alias;rnrn # location / rn # root html;rn # index index.html index.htm;rn # rn #rnrnrn # HTTPS serverrn #rn #server rn # listen 443;rn # server_name localhost;rnrn # ssl on;rn # ssl_certificate cert.pem;rn # ssl_certificate_key cert.key;rnrn # ssl_session_timeout 5m;rnrn # ssl_protocols SSLv2 SSLv3 TLSv1;rn # ssl_ciphers HIGH:!aNULL:!MD5;rn # ssl_prefer_server_ciphers on;rnrn # location / rn # root html;rn # index index.html index.htm;rn # rn #rnrnrn

没有更多推荐了,返回首页