ptpb / pb

pb is a formerly-lightweight pastebin and url shortener
Other
553 stars 52 forks source link

How to update AUR install #194

Closed Nic321 closed 7 years ago

Nic321 commented 7 years ago

So, updating yaourt traditionally:

$ yaourt -Syu

Doesn't prompt for the latest pb update. It's not included in the list of packages queued for updates. This, however:

$ yaourt -S pb-git

Gives me pb-git r357.dc04f7f-1 (2017-05-22 20:26). Will installing with -S override any config or /pb/ files? How do I properly update?

buhman commented 7 years ago

Doesn't prompt for the latest pb update.

Sounds like a yaourt problem? How can I reproduce this? I suppose it's possible yaourt disagrees with the versioning scheme (some r{your_current_version} !< r357), even though that version scheme is copy-paste from the wiki.

Will installing with -S override any config or /pb/ files?

No, unless I forgot something. The config files included in the package are /etc/xdg/pb/config.yaml and /etc/uwsgi/pb.ini, and are set as backup files. If yaourt dumpsters them, it's a yaourt bug.

update AUR install

You probably also want the optdepends, pbs-git.

How do I properly update?

Theoretically, you should just need to yaourt -Syu pb-git pbs-git.

Nic321 commented 7 years ago

That's interesting.

$ yaourt -Ss pb-git

aur/pb-git r357.dc04f7f-1 [installed: r349.87481a9-1] (3) (0.00)

Also:

$ yaourt -Syu pb-git pbs-git
:: Synchronizing package databases...
 core is up to date
 extra is up to date
 community is up to date
 multilib is up to date
error: target not found: pb-git
error: target not found: pbs-git
error: target not found: pb-git
error: target not found: pbs-git

About to try this now:

$ yaourt -S pb-git pbs-git
Nic321 commented 7 years ago

pb-git installed without errors. However:

pbs-git r13.15ba7a3-1  (2017-05-22 20:02)
( Unsupported package: Potentially dangerous ! )
==> Edit PKGBUILD ? [Y/n] ("A" to abort)
==> ------------------------------------
==> y

==> pbs-git dependencies:
 - libxml2 (already installed) [makedepend]
 - git (already installed) [makedepend]
 - npm (already installed) [makedepend]
 - graphicsmagick (already installed) [makedepend]
 - grunt-cli (package found) [makedepend]

==> Continue building pbs-git ? [Y/n]
==> ---------------------------------
==> 

==> Building and installing package
==> Install or build missing dependencies for pbs-git:
resolving dependencies...
looking for conflicting packages...

Package (1)          New Version  Net Change  Download Size

community/grunt-cli  1.2.0-3        0.59 MiB       0.07 MiB

Total Download Size:   0.07 MiB
Total Installed Size:  0.59 MiB

:: Proceed with installation? [Y/n] 
:: Retrieving packages...
 grunt-cli-1.2.0-3-any                                 69.3 KiB  744.8K/s 00:01 [############################################] 100%
(1/1) checking keys in keyring                                                 [############################################] 100%
(1/1) checking package integrity                                               [############################################] 100%
(1/1) loading package files                                                    [############################################] 100%
(1/1) checking for file conflicts                                              [############################################] 100%
error: failed to commit transaction (conflicting files)
grunt-cli: /usr/bin/grunt exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/CHANGELOG.md exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/README.md exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/bin/grunt exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/completion/bash exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/completion/zsh exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/lib/cli.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/lib/completion.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/lib/info.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/.bin/nopt exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/abbrev/LICENSE exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/abbrev/README.md exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/abbrev/abbrev.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/abbrev/package.json exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/balanced-match/.npmignore exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/balanced-match/LICENSE.md exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/balanced-match/README.md exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/balanced-match/index.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/balanced-match/package.json exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/brace-expansion/README.md exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/brace-expansion/index.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/brace-expansion/package.json exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/concat-map/.travis.yml exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/concat-map/LICENSE exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/concat-map/README.markdown exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/concat-map/example/map.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/concat-map/index.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/concat-map/package.json exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/concat-map/test/map.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/findup-sync/.npmignore exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/findup-sync/LICENSE-MIT exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/findup-sync/README.md exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/findup-sync/lib/findup-sync.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/findup-sync/package.json exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/glob/LICENSE exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/glob/README.md exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/glob/common.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/glob/glob.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/glob/package.json exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/glob/sync.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/grunt-known-options/LICENSE exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/grunt-known-options/README.md exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/grunt-known-options/index.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/grunt-known-options/package.json exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/inflight/LICENSE exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/inflight/README.md exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/inflight/inflight.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/inflight/package.json exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/inherits/LICENSE exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/inherits/README.md exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/inherits/inherits.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/inherits/inherits_browser.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/inherits/package.json exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/minimatch/LICENSE exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/minimatch/README.md exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/minimatch/minimatch.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/minimatch/package.json exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/nopt/.npmignore exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/nopt/.travis.yml exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/nopt/LICENSE exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/nopt/README.md exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/nopt/bin/nopt.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/nopt/examples/my-program.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/nopt/lib/nopt.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/nopt/package.json exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/nopt/test/basic.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/once/LICENSE exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/once/README.md exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/once/once.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/once/package.json exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/path-is-absolute/index.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/path-is-absolute/license exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/path-is-absolute/package.json exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/path-is-absolute/readme.md exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/.travis.yml exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/LICENSE exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/example/async.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/example/sync.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/index.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/lib/async.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/lib/caller.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/lib/core.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/lib/core.json exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/lib/node-modules-paths.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/lib/sync.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/package.json exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/readme.markdown exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/core.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/dotdot.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/dotdot/abc/index.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/dotdot/index.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/faulty_basedir.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/filter.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/filter_sync.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/mock.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/mock_sync.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/module_dir.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/module_dir/xmodules/aaa/index.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/module_dir/ymodules/aaa/index.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/module_dir/zmodules/bbb/main.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/module_dir/zmodules/bbb/package.json exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/node_path.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/node_path/x/aaa/index.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/node_path/x/ccc/index.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/node_path/y/bbb/index.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/node_path/y/ccc/index.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/nonstring.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/pathfilter.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/pathfilter/deep_ref/main.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/alt.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/deeper/ref.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/package.json exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/ref.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/precedence.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/precedence/aaa.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/precedence/aaa/index.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/precedence/aaa/main.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/precedence/bbb.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/precedence/bbb/main.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/resolver.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/resolver/bar/node_modules/foo/index.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/resolver/baz/doom.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/resolver/baz/package.json exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/resolver/baz/quux.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/resolver/biz/node_modules/garply/lib/index.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/resolver/biz/node_modules/garply/package.json exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/resolver/biz/node_modules/grux/index.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/resolver/biz/node_modules/tiv/index.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/resolver/cup.coffee exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/resolver/foo.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/resolver/incorrect_main/index.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/resolver/incorrect_main/package.json exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/resolver/mug.coffee exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/resolver/mug.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/resolver/other_path/lib/other-lib.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/resolver/other_path/root.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/resolver/punycode/node_modules/punycode/index.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/resolver/quux/foo/index.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/resolver/without_basedir/main.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/resolver/without_basedir/node_modules/mymodule.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/resolver_sync.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/subdirs.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/subdirs/node_modules/a/b/c/x.json exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/resolve/test/subdirs/node_modules/a/package.json exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/wrappy/LICENSE exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/wrappy/README.md exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/wrappy/package.json exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/node_modules/wrappy/wrappy.js exists in filesystem
grunt-cli: /usr/lib/node_modules/grunt-cli/package.json exists in filesystem
Errors occurred, no packages were upgraded.
==> Restart building pbs-git ? [y/N]
==> --------------------------------
==> 
buhman commented 7 years ago

Sounds like you did npm install -g grunt-cli at some point. If you want to replace that installation with the packaged installation, you can do pacman -S grunt-cli --force.

Nic321 commented 7 years ago

Thank you. --force did the trick. Safe to close this issue now.

There is a small bug in pb.py though. With the latest pb.py, my homepage html (layout.html) loads but the resources (background image, favicon) gives me 404's. For now, I'm using the pb.py from the last build I had backed up before updating. With the old pb.py .ssh doesn't leak pastes and my layout.html works fine. I'll try to debug when I have more time.

buhman commented 7 years ago

Yeah, I think pb could definitely use more optional debug logging, which would make problems like this quite obvious. I should probably also make the static directory runtime configurable.

You have /usr/share/pbs/{css,images,js} that each contain relevant-looking resources right?

Nic321 commented 7 years ago

Yeah, I'm sure all the resources are there. Like I mentioned, with the old pb.py, the homepage works. Using the new pb.py, I get 404's.

I noticed about .2 kb increase in size in the new pb.py. Probably some significant changes to the code, I should debug asap, huh? How do you suggest I debug? I'll have time thurs-fri to really spend time with it.

buhman commented 7 years ago

with the old pb.py

By the way, it sounds like you have static resources somewhere in /usr/lib/python*/pb/ or similar. These should probably be removed to avoid confusing test results.

How do you suggest I debug?

Well, one thing you could try is replacing the app = App(…) line with:

app = App(__name__, static_url_path='/static', static_folder='/usr/share/pbs')

If that works, I'd be interested to know what BaseDirectory.load_data_paths('pbs') returns for you.

Nic321 commented 7 years ago

Hey, sorry it's taken me so long to get back to you on this. In which file would the app = App line be located? I just recursively grepped all the files in the entire /usr/share/pbs/ directory but nothing came up. Using the AUR too, remember.

Nic321 commented 7 years ago

How do I tell pb to use /path/to/index.html as it's root directory?

buhman commented 7 years ago

Using the AUR too, remember.

Should be /usr/lib/python3.6/site-packages/pb/pb.py


I tested this on a clean system:

$ yaourt -S pb-git pbs-git
…
$ sudo systemctl start uwsgi@pb
…
$ curl -s localhost:8080/static/css/pbs.css | head -n 5
/*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */
html {
  font-family: sans-serif;
  -ms-text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;

I should also mention that if you don't care about modifying the less styles or icons etc…, you can skip pbs-git completely just add the line:

CDN_PREFIX: '//d34zelngniy2d8.cloudfront.net'

to your config.yaml.

buhman commented 7 years ago

How do I tell pb to use /path/to/index.html as it's root directory?

I don't know what this means, unless you're talking about /path/to/static/resources/directory. If this is desirable, I could make it a config option in addition to magical xdg discovery.

Nic321 commented 7 years ago

Sorry for being unclear. I basically want my pb server to use the files I have in /var/www/site/ and I don't know how to accomplish that.

buhman commented 7 years ago

pb server to use the files

I'm not sure what use means here--if /var/www/site/foo.html exists you want it be served on … http://yourpb/foo.html?

You could use nginx try_files for that, preferring /var/www/site over proxying to pb; something like this:

location / {
    root /var/www/site;
    try_files $uri @pb;
}

location @pb {
    proxy_pass http://localhost:8080;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Proto https; # remove if you're not serving https
}
Avrek commented 7 years ago

Hello, I just attempted your above @pb location config. Requests get proxied to my pb server but the root I specify isn't being used. The default pb root still gets displayed. Do you have any suggestions for getting this to work with nginx? Below is my nginx conf, have I misconfigured something?

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    charset utf-8;

    add_header X-XSS-Protection "1; mode=block" always;
    add_header X-Frame-Options DENY;
    add_header Referrer-Policy "SAMEORIGIN" always;
    add_header Content-Security-Policy "default-src http: data:'unsafe-inline' 'unsafe-eval'" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header Pragma no-cache;

    include /etc/nginx/conf.d/*.conf;

    server {
    listen       127.0.0.1:80;
    server_name  website.com;
    server_tokens  off;
    root /var/www/test/;
    index index.html;

    location / {
        expires 4h;
        add_header Pragma public;
        add_header Cache-Control "public";
    }
    location = / {
        rewrite ^ http://website.com/main/ permanent;
    }

    if ($request_method !~ ^(GET|POST)$) {
        return 444;
    }

    location / {
        root /var/www/test/;
        try_files $uri @pb;
    }

    location @pb {
        root /var/www/test/;
        index index.html;
        proxy_pass http://127.0.0.1:10222;
        proxy_set_header Host $host;
    }

    error_page  404 401 403 406 303 301               /404.html;
    error_page   500 502 503 504  /50x.html;
    }

}
Avrek commented 7 years ago

If it's simpler to configure with subdomains (eg paste.mywebsite.com), I would be interested in configure that instead. I'm not sure how to do that with proxy_pass and specify a root. Could you make a suggestion?

buhman commented 7 years ago

The default pb root still gets displayed

I think you mean index. This is because $uri evaluates the existance of files, not directories. The minimum change required would be to replace your current try_files line with:

try_files $uri $uri/ @pb;

I've also refactored your config, removing redundant directives/sections, and re-ordering for clarity:

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    charset utf-8;

    add_header X-XSS-Protection "1; mode=block" always;
    add_header X-Frame-Options DENY;
    add_header Referrer-Policy "SAMEORIGIN" always;
    add_header Content-Security-Policy "default-src http: data:'unsafe-inline' 'unsafe-eval'" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header Pragma no-cache;

    include /etc/nginx/conf.d/*.conf;

    server {
    listen       127.0.0.1:80;
    server_name  website.com;
    server_tokens  off;

    if ($request_method !~ ^(GET|POST)$) {
        return 444;
    }

    location = / {
        return 301 http://website.com/main/;
    }

    location / {
        expires 4h;
        add_header Pragma public;
        add_header Cache-Control "public";

            index index.html;
        root /var/www/test;
            try_files $uri $uri/ @pb;
    }

    location @pb {
        proxy_pass http://127.0.0.1:10222;
        proxy_set_header Host $host;
    }

    error_page  404 401 403 406 303 301               /404.html;
    error_page   500 502 503 504  /50x.html;
    }

}
buhman commented 7 years ago

http://website.com/main/

With respect to /var/www/test, the file /var/www/test/main/index.html should exist.

buhman commented 7 years ago

If it's simpler to configure with subdomains (eg paste.mywebsite.com), I would be interested in configure that instead.

It might be 'simpler' only in that fewer unique directives are used, but the result will probably end up being longer.

Doing this would look something like:

http {
    …
    server {
        …
        server_name paste.website.com;

        location / {
            …
            proxy_pass …;
        }
    } 

    server {
        …
        server_name website.com;

        location / {
            root …;
            index …;
        }
    }
}
Avrek commented 7 years ago

What's interesting is if I specify a root and index in the paste.website.com location block, the index in /var/www/test gets used (as expected):

http {
    ....

    server {
    listen 127.0.0.1:80;
    server_name paste.website.com;

    location / {
        index index.html;
        root /var/www/test;
        try_files $uri $uri/ @pb;
    }

    location @pb {
        proxy_pass http://127.0.0.1:11222;
        proxy_set_header Host $host;
    }
    } 

    server {
    listen 127.0.0.1:80;
    server_name website.com;

    location / {
        root /var/www/test;
        index index.html;
    }
    }
}

But POST requests don't make it to the pb server:

$ echo "blahblah" | curl -F c=@- 'http://paste.website.com'
<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx</center>
</body>
</html>

If I remove root and index from the location block, I'm able to create pastes. But of course the index looks nothing like what I need, it's your default pb index. Any ideas? Thank you for your help with this.

Avrek commented 7 years ago

Also tried your method without using subdomains. My site used the root and index I specified but again I was unable to pass POST requests to the pb server to create pastes.

buhman commented 7 years ago

Hmm that's fun.

This works for me (+4 lines):

        …
        error_page 418 = @pb;

        if ($request_method = POST) {
            return 418;
        }

        location / {
        …
→ curl -F c=@- localhost <<< asdf
date: 2017-07-16T07:07:58.954000+00:00
digest: 7d97e98f8af710c7e7fe703abc8f639e0ee507c4
long: AH2X6Y-K9xDH5_5wOryPY54O5QfE
short: 5QfE
size: 5
status: already exists
url: http://localhost/5QfE

Seems super ugly to me, but it works. For some reason DELETE and PUT don't get 405'ed and work as expected--probably dragons somewhere in http_core.

buhman commented 7 years ago

but again I was unable to pass POST requests to the pb server to create pastes.

The former behavior is just odd/unexpected try_files behavior, but with different server blocks, this definitely shouldn't happen; show me your config for this variant.

Avrek commented 7 years ago

Wow, interesting solution. That it pretty ugly and "hacky". Like this?

http {
    .... 

    include /etc/nginx/conf.d/*.conf;

    server {
    listen 127.0.0.1:80;
    server_name paste.website.com;

    location @pb {
        proxy_pass http://127.0.0.1:18080;
        proxy_set_header Host $host;
    }

    error_page 418 = @pb;

    if ($request_method = POST) {
        return 418;
    }

    location / {
        index index.html;
        root /var/www/test;
        try_files $uri $uri/ @pb;
    }
    }

    server {
    listen 127.0.0.1:80;
    server_name website.com;

    location / {
        root /var/www/test;
        index index.html;
    }
    }
}

$ echo "asdf" | curl -F c=@- http://paste.website.com

<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx</center>
</body>
</html>
Avrek commented 7 years ago

Any suggestions for the 502 I'm getting? Is the nginx.conf I posted what you described?

buhman commented 7 years ago

Is the nginx.conf I posted what you described?

No; you're doing two things at once here.

This:

http {
    .... 

    include /etc/nginx/conf.d/*.conf;

    server {
    listen 127.0.0.1:80;
    server_name paste.website.com;

    location / {
        proxy_pass http://127.0.0.1:18080;
        proxy_set_header Host $host;
    }
    }

    server {
    listen 127.0.0.1:80;
    server_name website.com;

    location / {
        root /var/www/test;
        index index.html;
    }
    }
}

Or this:

http {
    .... 

    include /etc/nginx/conf.d/*.conf;

    server {
    listen 127.0.0.1:80;
    server_name website.com;

    error_page 418 = @pb;

    if ($request_method = POST) {
        return 418;
    }

    location / {
        index index.html;
        root /var/www/test;
        try_files $uri $uri/ @pb;
    }

    location @pb {
        proxy_pass http://127.0.0.1:18080;
        proxy_set_header Host $host;
    }
    }
}
buhman commented 7 years ago

Any suggestions for the 502 I'm getting?

Are you sure pb is actually listening on 18080?

Avrek commented 7 years ago

The latter worked. Thank you very much.

buhman commented 7 years ago

No problem!