Rumah > Soal Jawab > teks badan
Jika nginx
konfigurasi berikut
Saya melawat http://kaipizhe.com
这个时候 request.getRequestURI();
这个值是 /kaipizhe/
而不是 /
Saya melawat http://kaipizhe.com/all/
这个时候 request.getRequestURI();
这个值是 /kaipizhe/all/
而不是 /all/
ialah request.getRequestURI();
都会带上 /kaipizhe/
,怎么让他直接是 /
,
Adakah saya nginx
Ada masalah konfigurasi, apa yang perlu saya lakukan?
nginx
log_format kaipizhe.com '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $http_x_forwarded_for'; server { listen 80; server_name kaipizhe.com; root /usr/local/tomcat/webapps/kaipizhe; include none.conf; location / { proxy_pass http://localhost:8080/kaipizhe/; proxy_cookie_path /kaipizhe /; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_redirect http://localhost:8080/kaipizhe/ http://kaipizhe.com/; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } access_log /home/wwwlogs/kaipizhe.com.log kaipizhe.com; }
阿神2017-05-16 17:25:41
Adalah disyorkan untuk mengubah suai konfigurasi tomcat, mengkonfigurasi hos maya untuk projek anda dan menetapkan direktori akar projek kepada /usr/local/tomcat/webapps/kaipizhe (atau direktori akar sebenar projek anda), jadi bahawa anda tidak perlu menambah a / apabila mengakses awalan kaipizhe, secara semula jadi hasil yang diperolehi oleh request.getRequestURI() juga adalah yang anda inginkan.
Jika anda menggunakan akses di atas, ingat untuk mengubah suai konfigurasi nginx, ia sepatutnya baik.
location / {
proxy_pass http://localhost:8080/;
proxy_cookie_path / /;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect http://localhost:8080/ http://kaipizhe.com/;
}
迷茫2017-05-16 17:25:41
Anda juga boleh melaksanakannya tanpa mengubah suai konfigurasi tomcat, menambah hos maya atau menggunakan peraturan penulisan semula nginx;
server {
listen 88;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location /SMSSupport/ { #静态资源会自动request.getRequestURI()头
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_http_version 1.1;
}
location / { #非静态请求,自动转发到对应tomcat项目下
proxy_pass http://127.0.0.1:8080/SMSSupport/;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
}
}