#1983 Getting pagure to work with nginx and uwsgi
Closed: Fixed 8 years ago Opened 8 years ago by lurchi.

I installed pagure on my server as described in the "Installing pagure via setup.py" section in the docs. I'm using nginx and uwsgi to serve it. I configured nginx to redirect all requests to https://mydomain.tld/pagure to the uwsgi script. The projects page is served correctly, but all the relative links, e.g. the "Users" and "Groups" tabs are broken. They point to /users and /groups.

My expectation was that pagure uses the APP_URL config option to construct the references, that is e.g. /pagure/users and /pagure/groups. Is there something I can do?

The relevant parts of my nginx config:

location /pagure/ {
    rewrite ^/pagure/(.*) /$1  break;
    include /etc/nginx/uwsgi_params;
    uwsgi_pass  pagure-handler;
}
...
upstream pagure-handler {
    server 127.0.0.1:29000;
}

So nginx is rewriting /pagure to /. My pagure.cfg is attached.

pagure.cfg


Metadata Update from @pingou:
- Issue tagged with: bug

8 years ago

So we have an instance here https://src.stg.fedoraproject.org/pagure/ that is deployed under /pagure/ whose config file is: https://infrastructure.fedoraproject.org/cgit/ansible.git/tree/roles/distgit/pagure/templates/pagure.cfg and as far as I can see the users and groups page are at their expected location, so I would tend to think that this is something to do with your setup.

Unfortunately, I have no experience with nginx so I don't really know how to help you with this :(

Thank you, it was indeed an nginx configuration issue. This location section works:

location /pagure/ {
    include /etc/nginx/uwsgi_params;
    uwsgi_pass  pagure-handler;
    uwsgi_param SCRIPT_NAME /pagure;
    uwsgi_modifier1 30;
}

Metadata Update from @lurchi:
- Issue close_status updated to: Fixed
- Issue status updated to: Closed (was: Open)

8 years ago

one more note for people running nginx and uwsgi:

you can leave out uwsgi_modifier1 30; (it's a hack), if you start uwsgi with the --route-run="fixpathinfo:1" parameter.

example:

uwsgi_python27 --socket 127.0.0.1:29000 --route-run="fixpathinfo:1" --wsgi-file=/usr/share/pagure/pagure.wsgi

If you're confident about your setup, feel free to propose a section in the doc on how to setup pagure with nginx :)

On CentOS 7 you will need to install the uwsgi uwsgi-plugin-python packages and then configure uwsgi to serve the app. Here is a copy of my uwsgi.ini file.

[uwsgi]
plugin = python

# socket = [addr:port]
socket = 127.0.0.1:8081

## Base application directory
chdir  = /usr/share/pagure
wsgi-file = pagure.wsgi

## WSGI module and callable
## module = [wsgi_module_name]:[application_callable_name]
##module = pagure:pagure.wsgi
#
## master = [master process (true of false)]
master = true
#
## processes = [number of processes]
processes = 5
#
uid = git
gid = git

The nginx configuration to go along with this is as follows.

upstream pagure-handler {
        server 127.0.0.1:8081;
    }

    server {
        listen       89 default_server;
        listen       [::]:89 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
            include /etc/nginx/uwsgi_params;
            uwsgi_pass  pagure-handler;
            uwsgi_param SCRIPT_NAME /pagure;
            uwsgi_modifier1 30;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
    }

Not that this configuration uses an alternate http port (89). You will need to update the SELinux configuration to allow nginx to use this port.

semanage port -a -t http_port_t -p tcp 89

Sorry for the long delay. It seems quite some people are interested in a pagure+nginx setup and obviously I didn't provide enough information. Here is my nginx config, that worked for me with pagure 2.13.2.

    server {
        listen 80;
        listen [::]:80;
        server_name mydomain.tld
        return 301 https://$host$request_uri;
    }

    server {
        listen 443;
        listen [::]:443;
        server_name mydomain.tld;

        ssl on;
        ssl_certificate /etc/ssl/private/mydomain.tld.pem;
        ssl_certificate_key /etc/ssl/private/mydomain.tld.pem;

        access_log /var/log/nginx/access_log main;
        error_log /var/log/nginx/error_log warn;

        root /var/www/mydomain.tld/htdocs/;

        location /pagure/ {
            include /etc/nginx/uwsgi_params;
            uwsgi_pass  pagure-handler;
            uwsgi_param SCRIPT_NAME /pagure;
        }

        location /static {
            alias   /usr/lib/python2.7/site-packages/pagure-2.13.2-py2.7.egg/pagure/static/;
        }

        location /pagure/releases {
            alias   /var/www/releases;
        }

        add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
    }

    upstream pagure-handler {
        server 127.0.0.1:29000;
    }

With this config nginx delivers pagure under https://mydomain.tld/pagure. The relevant parts in pagure.cfg are these:

APP_URL = "https://mydomain.tld/pagure"
APPLICATION_ROOT = "/pagure/"

As I mentioned above I'm using uwsgi. I start it manually like this:

uwsgi_python27 --socket 127.0.0.1:29000 --route-run="fpathinfo:1" --wsgi-file=/usr/share/pagure/pagure.wsgi

pagure.wsgi is the unchanged file shipped with pagure.

I can add a section in the docs in the next days. Can someone try, if my configuration still works with the current version of pagure?

I changed the title so people can find this issue when they search for nginx or uwsgi.

Thanks for the update @lurchi - I will give this a try, and report back.

Revisiting this a year later it looks like a few things have changed in CentOS 7.6. The package name for the uwsgi plugin is now uwsgi-plugin-python2. The nginx configuration I posted previously is also not quite correct. Here is a copy of my working nginx configuration.

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    upstream pagure-handler {
        server 127.0.0.1:8081;
    }

    server {
        listen       89 default_server;
        listen       [::]:89 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
            include /etc/nginx/uwsgi_params;
            uwsgi_pass  pagure-handler;
            uwsgi_param SCRIPT_NAME /pagure;
            uwsgi_modifier1 30;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
}

Log in to comment on this ticket.

Metadata
Attachments 1
Attached 8 years ago View Comment