我的当前nginx配置有问题.我想要做的是:
我在stackoverflow上尝试了几种配置,但它们都不符合我的需求.
这是我目前的配置:
# IP which nodejs is running on
upstream app_x {
server 127.0.0.1:3000;
}
# nginx server instance
server {
listen 80;
server_name x.x.x.x;
#access_log /var/log/nginx/x.log;
root /var/www/x/public;
location / {
root /var/www/x/public;
index index.html index.htm index.php;
}
location ^/(.*)$ {
if (-f $request_filename) {
break;
}
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:3000;
}
}
Run Code Online (Sandbox Code Playgroud)
mek*_*all 12
我想我弄明白你要做什么.正确的方法是try_files与命名位置一起使用.
尝试使用以下配置:
# IP which nodejs is running on
upstream app_x {
server 127.0.0.1:3000;
}
# nginx server instance
server {
listen 80;
server_name x.x.x.x;
#access_log /var/log/nginx/x.log;
location / {
root /var/www/x/public;
index index.html index.htm index.php;
try_files $uri $uri/ @node;
}
location @node {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://app_x;
}
}
Run Code Online (Sandbox Code Playgroud)
注意:当你有一个上游定义时,你应该在你的proxy_ pass.此外,在代理时,始终添加X-Forwarded-For标头.
| 归档时间: |
|
| 查看次数: |
12371 次 |
| 最近记录: |