ralobh
By:
ralobh

Make Odoo run on port 80 with Nginx.

October 1, 2015 8.6k views
Nginx LEMP Ubuntu

Hello,
first of all sorry for my bad English. I'm new to vps and I've been learning to setup my own just now.

So I installed LEMP and Odoo in my VM, i installed WordPress on the lemp stack. Odoo is running in the different port of 8069. Right now if I open my public ip on http://my\_public\_id (i dont have a domain yet) it will right away show me the wordpress page.

What I want to achieve is, i want to be able to access my odoo via http://my\_public\_id/odoo rather than http://my\_public\_id:8069 I know, i probably should have use port 443 https rather than port 80 http, but I want to know how it works first.

I've been searching for answers in google, It's about the server block and proxy passing, but I don't know, the learning curve is too steep and my limitation to understand the English jargons doesn't quite cut it. Please bear with my skill on this.

Thank you very much
Ralobh

2 Answers

Check out NGINX: Proxy folders to different root - Raymii.org.

You need to add the following to your nginx virtual host config:

location /odoo/ {
    rewrite ^/odoo(/.*)$ $1 break;
    proxy_pass  http://localhost:8069/;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
    proxy_redirect    off;
}

Make sure to restart nginx so that the changes take effect.

  • THANKS for the answer kamaln7 :)

    It worked the first time, after I restart the nginx service again, the css style and images weren't loaded. The page is plain text html without css, and if I press a link from it, it redirects me to http://my_public_id page instead of the page it supposed to if I open it from http://my_public_id:8069

    this is my nginx configuration btw

    server {
            listen 80 default_server;
            listen [::]:80 default_server ipv6only=on;
    
            root /var/www/***/***;
            index index.php index.html index.htm;
    
            server_name ***;
    
            error_page 404 /404.html;
    
            error_page 500 502 503 504 /50x.html;
            location = /50x.html {
                    root /usr/share/nginx/html;
            }
    
    
            location / {
                # try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.php?$args;
            }
    
            #location /profile {
            #   proxy_pass http://127.0.0.1:8069;
            #   proxy_redirect off;
            #   proxy_set_header    Host            $host;
            #   proxy_set_header    X-Real-IP       $remote_addr;
            #   proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
            #   proxy_set_header X-Forwarded-Proto $scheme;
            #}# I used ^ this before you replied :)
    
            location /profile/ {
                rewrite ^/profile(/.*)$ $1 break;
                proxy_pass  http://localhost:8069/;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto https;
                proxy_redirect    off;
            }
    
            location ~ \.php$ {
                    try_files $uri =404;
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
                    fastcgi_pass unix:/var/run/php5-fpm.sock;
                    fastcgi_index index.php;
                    include fastcgi_params;
            }
    }
    

    I picked up a thing or two about configuring nginx these past two days, I think i need to familiarize myself to rewrite and regex.

    thank you very much

    • Does Odoo let you set the "application URL" for your website? If so, try setting it to "http://your\_domain\_or\_ip/odoo".

      • I've been searching to do it, but no luck. I can change my root in wordpress but not in Odoo. I'm probably missing out, or there really is no way to change it. I will post again if I see how to do it, thanks.

        • I found this post on the Odoo forums:

          The Settings->Parameters->System Parameters menu is hidden by default.

          First enable the Technical Features for your admin account in the Settings → Users → Users → Administrator → Access Right

          There should be a web.base.url setting in System Parameters which you can set to the correct URL.

          Let me know if that helps.

          • I tried it, doesn't help. I change it to http://my-domain/dir, it didn't do anything really, even If i change it to the same port http://my-domain:8069/dir it redirects me to 404 when i try to open it. When I try accessing it via the nginx the style still isn't loaded. here screenshot:

            http://prntscr.com/8o207v

            I did restart odoo and nginx after changing the configuration, i tried proxy mode in odoo, and almost everything i could find on the internet to do this. but still no luck

            If i proxy the odoo to / it works just fine, but I want my wordpress to be in the / and odoo in /dir. maan this is hard :D

            thank you very much.. for your answers :) i hope you can bear with me a while hehe.

  • [deleted]
Have another answer? Share your knowledge.