问题描述
这个是我的go语言项目(MVC)的path:/home/demo/goproj/src/Test 监听的是8080端口,Nginx的配置文件该怎么写呢??我配置了几次还是不对。' location /{} ' 还是这样写' location /Test {}'
问题解答
回答1:简单版本:
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;}
一般静态文件由 nginx 提供,所以可以这样写
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;}回答2:
server { listen 80; server_name 123.com; location / { proxy_pass http://127.0.0.1:8080; proxy_redirect default;}}
如果有2级目录则
location /test {proxy_pass http://127.0.0.1:8080;proxy_redirect default;}