FreeMind
FreeMind

Reputation: 233

Nginx default website path in subdirectory rather than / (root)

I want to configure my site so it runs in a subdirectory rather than mydomain/. I mean instead of going to mysite.com/ and seeing the website, I want it to be seen from mydomain/myproject. I am using uwsgi to talk to a flask website and here is my /etc/nginx/sites-available/myproject config file.

server {
    server_name mydomain www.mydomain;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/root/Desktop/myproject/myproject.sock;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/mydomain/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mydomain/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}
server {
    if ($host = www.mydomain) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = mydomain) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name mydomain www.mydomain;
    return 404; # managed by Certbot

}

I tried to change the code from location / to location /myproject or location = /myproject but it gave me not found!

Added information Here is my config.ini file

[uwsgi]
module = server:app

master = true
processes = 5

socket = myproject.sock
chmod-socket = 660
vacuum = true

die-on-term = true

route-run = fixpathinfo:

I am using uwsgi version 2.0.18 and nginx/1.14.0 (Ubuntu) Thanks

Upvotes: 0

Views: 920

Answers (1)

tgyger
tgyger

Reputation: 241

try this...

NGINX config:


location /mylocation {
        include uwsgi_params;
        uwsgi_pass unix:/myproject/myproject.sock;
        uwsgi_param SCRIPT_NAME /mylocation;
    }

uwsgi ini file:

route-run = fixpathinfo:

Edit: i tried it with rewriting the path in my nginx config and it worked.. nothing special to configure in your wsgi ini file!

location /be {
    rewrite /be/(.+) /$1 break;
        include uwsgi_params;
        uwsgi_pass unix:/myproject/myproject.sock;

    }

EDIT: So, my conclusion is, fixpathinfo in uwsgi ini seems not to work when using "/" (root) inside FlaskApp. If Flask is using "/", you should set rewrite /be/(.*) /$1 break; in your NGINX Config

Thank you CyberDem0n!! Nginx - Rewrite the request_uri before uwsgi_pass

Upvotes: 1

Related Questions