我正在嘗試在單個 AWS EC2 實體上部署 tomcat 和 Nginx 服務器。我有 3 個實體,在每個實體上,我想部署 Nginx 和 Tomcat 服務器。下面是我的組態檔
/etc/nginx/nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
}"
/etc/nginx/conf.d/application.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
root /var/lib/tomcat9/webapps/ROOT;
index deploy.html;
location /admin {
try_files $uri $uri/ /deploy.html;
}
location /admin/admin-portal {
alias /opt/tomcat/webapps/ROOT/;
rewrite /admin-portal/(.*) /$1 break;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8080/;
}
location ~ \.css {
add_header Content-Type text/css;
}
location ~ \.js {
add_header Content-Type application/x-javascript;
}
我的目標是,當我點擊 http://IP/ 或 HTTP://IP/admin 然后它應該重定向到 deploy.html 當我點擊 HTTP://IP/admin/admi-portal 它應該打開 tomcat 服務器
注意:我在這兩種情況下都取得了成功,除非我點擊 HTTP://IP/admin/admi-portal 然后它只打開 HTML 頁面和 CSS/png/js 檔案得到 404:not found 錯誤
/opt/tomcat/webapps/ROOT/這是所有tomcat靜態檔案CSS/js/png等的檔案路徑
誰能幫我這個?
uj5u.com熱心網友回復:
嘗試點擊 EC2 實體的競爭 url
<instanceip>:8080/admin/admin-portal/
另外,您可以在最后添加“/”:-
location /admin/admin-portal/
然后嘗試使用
<instance-ip>:8080/admin/admin-portal
現在您不需要在末尾添加“/”
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/436499.html
標籤:nginx 雄猫 nginx-反向代理 nginx 配置
