這個(gè)是我的go語(yǔ)言專(zhuān)案(MVC)的path:/home/demo/goproj/src/Test 監(jiān)聽(tīng)的是8080端口,Nginx的設(shè)定檔該怎麼寫(xiě)呢? ?我配置了幾次還是不對(duì)。 " location /{} " 還是這樣寫(xiě)" location /Test {}"
簡(jiǎn)單版本:
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://localhost:8080;
}
一般靜態(tài)檔案由 nginx 提供,所以可以這樣寫(xiě)
root /home/demo/goproj/src/Test/public;
try_files $uri/index.html $uri.html $uri @goapp;
location @goapp {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://localhost:8080;
}
server {
listen 80;
server_name 123.com;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_redirect default;
}
}
如果有2級(jí)目錄則
location /test {
proxy_pass http://127.0.0.1:8080;
proxy_redirect default;
}