我正在本地计算机grails 2.2.2
上使用Mac OSX Lion 10.7.5
开展项目我使用NGINX
安装了brew
并修改了nginx.conf
,如下所示:
worker_processes 1;
error_log logs/error.log info;
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;
keepalive_timeout 65;
server {
listen 8081;
server_name localhost;
root /;
access_log /Users/lorenzo/grails/projects/logs/myproject_access.log;
location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://localhost:8081;
}
#images folders
location /posters {
root /Users/lorenzo/grails/projects/posters/;
}
#images folders
location /avatars {
root /Users/lorenzo/grails/projects/avatars/;
}
#images folders
location /waveforms {
root /Users/lorenzo/grails/projects/waveforms/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
当我访问http://localhost:8081
我的网站正在运行但我想确保images
由nginx
而非tomcat
提供,因此我会查看{{1}但是什么也没发生。
myproject_access.log
不正在运行时, ngnix
正在写入日志仅。
有没有办法“监控”tomcat
提供的静态文件?
谢谢
修改
nginx
当tomcat运行时输出是:
Executing curl -I http://localhost:8081
当tomcat没有运行时输出是:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1 //TOMCAT
...
答案 0 :(得分:3)
你的问题是你正在让两个服务器都在同一个端口上监听,你需要将tomcat移动到另一个端口,如8082
,让nginx监听主端口(8081
in您的情况),然后在请求不是图像(或任何资产)时告诉nginx代理8082
。
这里也是对服务器块的改进
server {
server_name localhost;
listen 8081;
root /Users/lorenzo/grails/projects;
location @tomcat {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://localhost:8082;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location / {
try_files $uri $uri/ @tomcat;
}
}