gpt4 book ai didi

macos - TOMCAT 前面的 NGINX 提供静态文件

转载 作者:行者123 更新时间:2023-11-28 22:37:40 24 4
gpt4 key购买 nike

我正在本地机器上使用 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 时,我的网站正在运行,但我想确保 imagesnginx 提供服务而不是通过 tomcat 所以我查看了 myproject_access.log 但没有任何反应。

ngnix ONLYtomcat 正在NOT 运行时写入日志。

有没有办法“监控”由 nginx 服务的静态文件?

谢谢

编辑

Executing curl -I http://localhost:8081

当 tomcat 运行时输出是:

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1 //TOMCAT
...

当 tomcat 未运行时,输出为:

HTTP/1.1 500 Internal Server Error
Server: nginx/1.4.1 //NGINX
Date: Tue, 08 Apr 2014 09:30:00 GMT
Content-Type: text/html
Content-Length: 192
Connection: keep-alive

最佳答案

你的问题是你正在让两个服务器监听同一个端口,你需要将 tomcat 移动到另一个端口,比如 8082 并让 nginx 监听主端口(即 8081 在你的情况下),然后当请求不是图像(或任何 Assets )时告诉 nginx 代理到 8082

这里还有对您的服务器 block 的改进

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;
}
}

关于macos - TOMCAT 前面的 NGINX 提供静态文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22932415/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com