Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.2k views
in Technique[技术] by (71.8m points)

Nginx : Location = / not working with location /

I have a nginx host file with two locations and I want to have the exact / goes to index.html and /something goes to my proxy.

I have a landing page in HTML that I want to use for my_domain.com and my React App is served in a proxy pass, so I want that my_domain.com/something point to my proxy (react app).

something used above can be any string

I've tried this but it's not working it's always redirecting to my second location :

server_name domain.com www.domain.com;
index index.php index.html index.htm;

location = / {
    root /var/www/domain;
    index index.html;
    try_files $uri /index.html;
}

location / {
    proxy_pass http://localhost:3020;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_redirect off;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

I hope you can help me.

Thanks.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...