Cannot display gitea pages behind nginx reverse proxy with custom URL #1606

Closed
opened 2025-11-02 04:06:24 -06:00 by GiteaMirror · 3 comments
Owner

Originally created by @lfdmn on GitHub (Mar 8, 2018).

  • Gitea version (or commit ref): 1.4
  • Git version: 2.7.4
  • Operating system: linux
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:
git@linux-pc ~ $ ./gitea web
2018/03/08 08:11:52 [T] AppPath: /home/git/gitea
2018/03/08 08:11:52 [T] AppWorkPath: /home/git
2018/03/08 08:11:52 [T] Custom path: /home/git/custom
2018/03/08 08:11:52 [T] Log path: /home/git/log
2018/03/08 08:11:52 Serving [::]:3000 with pid 23980
[Macaron] 2018-03-08 08:11:55: Started GET /gitea/ for 10.10.40.101
[Macaron] 2018-03-08 08:11:55: Completed GET /gitea/ 404 Not Found in 6.616304ms
[Macaron] 2018-03-08 08:11:55: Started GET /gitea/vendor/assets/font-awesome/css/font-awesome.min.css for 10.10.40.101
[Macaron] 2018-03-08 08:11:55: Completed GET /gitea/vendor/assets/font-awesome/css/font-awesome.min.css 404 Not Found in 1.253843ms
[Macaron] 2018-03-08 08:11:55: Started GET /gitea/vendor/assets/octicons/octicons.min.css for 10.10.40.101
[Macaron] 2018-03-08 08:11:55: Completed GET /gitea/vendor/assets/octicons/octicons.min.css 404 Not Found in 962.644µs
[Macaron] 2018-03-08 08:11:55: Started GET /gitea/vendor/plugins/semantic/semantic.min.css for 10.10.40.101
[Macaron] 2018-03-08 08:11:55: Completed GET /gitea/vendor/plugins/semantic/semantic.min.css 404 Not Found in 946.2µs
[Macaron] 2018-03-08 08:11:55: Started GET /gitea/css/index.css?v=2e5519fee9d0a583e6fd78e986c316c0 for 10.10.40.101
[Macaron] 2018-03-08 08:11:55: Started GET /gitea/vendor/plugins/cssrelpreload/loadCSS.min.js for 10.10.40.101
[Macaron] 2018-03-08 08:11:55: Completed GET /gitea/css/index.css?v=2e5519fee9d0a583e6fd78e986c316c0 404 Not Found in 1.153015ms
[Macaron] 2018-03-08 08:11:55: Completed GET /gitea/vendor/plugins/cssrelpreload/loadCSS.min.js 404 Not Found in 1.153595ms
[Macaron] 2018-03-08 08:11:55: Started GET /gitea/vendor/plugins/cssrelpreload/cssrelpreload.min.js for 10.10.40.101
[Macaron] 2018-03-08 08:11:55: Started GET /gitea/img/gitea-sm.png for 10.10.40.101
[Macaron] 2018-03-08 08:11:55: Started GET /gitea/img/404.png for 10.10.40.101
[Macaron] 2018-03-08 08:11:55: Completed GET /gitea/vendor/plugins/cssrelpreload/cssrelpreload.min.js 404 Not Found in 1.449843ms
[Macaron] 2018-03-08 08:11:55: Completed GET /gitea/img/gitea-sm.png 404 Not Found in 1.349044ms
[Macaron] 2018-03-08 08:11:55: Completed GET /gitea/img/404.png 404 Not Found in 1.540947ms
[Macaron] 2018-03-08 08:11:55: Started GET /gitea/vendor/plugins/jquery/jquery.min.js for 10.10.40.101
[Macaron] 2018-03-08 08:11:55: Completed GET /gitea/vendor/plugins/jquery/jquery.min.js 404 Not Found in 1.297921ms
[Macaron] 2018-03-08 08:11:55: Started GET /gitea/vendor/plugins/jquery.areyousure/jquery.are-you-sure.js for 10.10.40.101
[Macaron] 2018-03-08 08:11:55: Started GET /gitea/vendor/plugins/autolink/autolink.js for 10.10.40.101
[Macaron] 2018-03-08 08:11:55: Completed GET /gitea/vendor/plugins/jquery.areyousure/jquery.are-you-sure.js 404 Not Found in 1.424139ms
[Macaron] 2018-03-08 08:11:55: Started GET /gitea/vendor/plugins/emojify/emojify.min.js for 10.10.40.101
[Macaron] 2018-03-08 08:11:55: Completed GET /gitea/vendor/plugins/autolink/autolink.js 404 Not Found in 1.434475ms
[Macaron] 2018-03-08 08:11:55: Started GET /gitea/vendor/plugins/clipboard/clipboard.min.js for 10.10.40.101
[Macaron] 2018-03-08 08:11:55: Completed GET /gitea/vendor/plugins/emojify/emojify.min.js 404 Not Found in 1.347204ms
[Macaron] 2018-03-08 08:11:55: Completed GET /gitea/vendor/plugins/clipboard/clipboard.min.js 404 Not Found in 1.55911ms
[Macaron] 2018-03-08 08:11:55: Started GET /gitea/vendor/plugins/vue/vue.min.js for 10.10.40.101
[Macaron] 2018-03-08 08:11:55: Completed GET /gitea/vendor/plugins/vue/vue.min.js 404 Not Found in 1.579917ms
[Macaron] 2018-03-08 08:11:55: Started GET /gitea/vendor/plugins/semantic/semantic.min.js for 10.10.40.101
[Macaron] 2018-03-08 08:11:55: Completed GET /gitea/vendor/plugins/semantic/semantic.min.js 404 Not Found in 1.627888ms
[Macaron] 2018-03-08 08:11:55: Started GET /gitea/js/index.js?v=2e5519fee9d0a583e6fd78e986c316c0 for 10.10.40.101
[Macaron] 2018-03-08 08:11:55: Completed GET /gitea/js/index.js?v=2e5519fee9d0a583e6fd78e986c316c0 404 Not Found in 1.685519ms

Description

I would need to run gitea behind nginx reverse proxy - final url https://domain/gitea/

I have tried setting app.ini like this

[server]
SSH_DOMAIN     = domain
DOMAIN         = domain
HTTP_PORT      = 3000
ROOT_URL       = https://domain/gitea/
LOCAL_ROOT_URL = http://localhost:3000/

nginx location

location /gitea {
     proxy_pass          http://localhost:3000;
     proxy_read_timeout  90;
     proxy_set_header Host $server_name;
     proxy_set_header X-Real-IP $remote_addr;
}

The stylesheet is broken and js files cannot be found.

The generated HTML urls look fine, for instance /gitea/vendor/plugins/semantic/semantic.min.js. But it seems that the server is not able to serve these files with the custom URL.

Screenshots

unknown

Originally created by @lfdmn on GitHub (Mar 8, 2018). - Gitea version (or commit ref): 1.4 - Git version: 2.7.4 - Operating system: linux - Database (use `[x]`): - [ ] PostgreSQL - [x] MySQL - [ ] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [x] Not relevant - Log gist: ``` git@linux-pc ~ $ ./gitea web 2018/03/08 08:11:52 [T] AppPath: /home/git/gitea 2018/03/08 08:11:52 [T] AppWorkPath: /home/git 2018/03/08 08:11:52 [T] Custom path: /home/git/custom 2018/03/08 08:11:52 [T] Log path: /home/git/log 2018/03/08 08:11:52 Serving [::]:3000 with pid 23980 [Macaron] 2018-03-08 08:11:55: Started GET /gitea/ for 10.10.40.101 [Macaron] 2018-03-08 08:11:55: Completed GET /gitea/ 404 Not Found in 6.616304ms [Macaron] 2018-03-08 08:11:55: Started GET /gitea/vendor/assets/font-awesome/css/font-awesome.min.css for 10.10.40.101 [Macaron] 2018-03-08 08:11:55: Completed GET /gitea/vendor/assets/font-awesome/css/font-awesome.min.css 404 Not Found in 1.253843ms [Macaron] 2018-03-08 08:11:55: Started GET /gitea/vendor/assets/octicons/octicons.min.css for 10.10.40.101 [Macaron] 2018-03-08 08:11:55: Completed GET /gitea/vendor/assets/octicons/octicons.min.css 404 Not Found in 962.644µs [Macaron] 2018-03-08 08:11:55: Started GET /gitea/vendor/plugins/semantic/semantic.min.css for 10.10.40.101 [Macaron] 2018-03-08 08:11:55: Completed GET /gitea/vendor/plugins/semantic/semantic.min.css 404 Not Found in 946.2µs [Macaron] 2018-03-08 08:11:55: Started GET /gitea/css/index.css?v=2e5519fee9d0a583e6fd78e986c316c0 for 10.10.40.101 [Macaron] 2018-03-08 08:11:55: Started GET /gitea/vendor/plugins/cssrelpreload/loadCSS.min.js for 10.10.40.101 [Macaron] 2018-03-08 08:11:55: Completed GET /gitea/css/index.css?v=2e5519fee9d0a583e6fd78e986c316c0 404 Not Found in 1.153015ms [Macaron] 2018-03-08 08:11:55: Completed GET /gitea/vendor/plugins/cssrelpreload/loadCSS.min.js 404 Not Found in 1.153595ms [Macaron] 2018-03-08 08:11:55: Started GET /gitea/vendor/plugins/cssrelpreload/cssrelpreload.min.js for 10.10.40.101 [Macaron] 2018-03-08 08:11:55: Started GET /gitea/img/gitea-sm.png for 10.10.40.101 [Macaron] 2018-03-08 08:11:55: Started GET /gitea/img/404.png for 10.10.40.101 [Macaron] 2018-03-08 08:11:55: Completed GET /gitea/vendor/plugins/cssrelpreload/cssrelpreload.min.js 404 Not Found in 1.449843ms [Macaron] 2018-03-08 08:11:55: Completed GET /gitea/img/gitea-sm.png 404 Not Found in 1.349044ms [Macaron] 2018-03-08 08:11:55: Completed GET /gitea/img/404.png 404 Not Found in 1.540947ms [Macaron] 2018-03-08 08:11:55: Started GET /gitea/vendor/plugins/jquery/jquery.min.js for 10.10.40.101 [Macaron] 2018-03-08 08:11:55: Completed GET /gitea/vendor/plugins/jquery/jquery.min.js 404 Not Found in 1.297921ms [Macaron] 2018-03-08 08:11:55: Started GET /gitea/vendor/plugins/jquery.areyousure/jquery.are-you-sure.js for 10.10.40.101 [Macaron] 2018-03-08 08:11:55: Started GET /gitea/vendor/plugins/autolink/autolink.js for 10.10.40.101 [Macaron] 2018-03-08 08:11:55: Completed GET /gitea/vendor/plugins/jquery.areyousure/jquery.are-you-sure.js 404 Not Found in 1.424139ms [Macaron] 2018-03-08 08:11:55: Started GET /gitea/vendor/plugins/emojify/emojify.min.js for 10.10.40.101 [Macaron] 2018-03-08 08:11:55: Completed GET /gitea/vendor/plugins/autolink/autolink.js 404 Not Found in 1.434475ms [Macaron] 2018-03-08 08:11:55: Started GET /gitea/vendor/plugins/clipboard/clipboard.min.js for 10.10.40.101 [Macaron] 2018-03-08 08:11:55: Completed GET /gitea/vendor/plugins/emojify/emojify.min.js 404 Not Found in 1.347204ms [Macaron] 2018-03-08 08:11:55: Completed GET /gitea/vendor/plugins/clipboard/clipboard.min.js 404 Not Found in 1.55911ms [Macaron] 2018-03-08 08:11:55: Started GET /gitea/vendor/plugins/vue/vue.min.js for 10.10.40.101 [Macaron] 2018-03-08 08:11:55: Completed GET /gitea/vendor/plugins/vue/vue.min.js 404 Not Found in 1.579917ms [Macaron] 2018-03-08 08:11:55: Started GET /gitea/vendor/plugins/semantic/semantic.min.js for 10.10.40.101 [Macaron] 2018-03-08 08:11:55: Completed GET /gitea/vendor/plugins/semantic/semantic.min.js 404 Not Found in 1.627888ms [Macaron] 2018-03-08 08:11:55: Started GET /gitea/js/index.js?v=2e5519fee9d0a583e6fd78e986c316c0 for 10.10.40.101 [Macaron] 2018-03-08 08:11:55: Completed GET /gitea/js/index.js?v=2e5519fee9d0a583e6fd78e986c316c0 404 Not Found in 1.685519ms ``` ## Description I would need to run gitea behind nginx reverse proxy - final url https://domain/gitea/ I have tried setting app.ini like this ``` [server] SSH_DOMAIN = domain DOMAIN = domain HTTP_PORT = 3000 ROOT_URL = https://domain/gitea/ LOCAL_ROOT_URL = http://localhost:3000/ ``` nginx location ``` location /gitea { proxy_pass http://localhost:3000; proxy_read_timeout 90; proxy_set_header Host $server_name; proxy_set_header X-Real-IP $remote_addr; } ``` The stylesheet is broken and js files cannot be found. The generated HTML urls look fine, for instance /gitea/vendor/plugins/semantic/semantic.min.js. But it seems that the server is not able to serve these files with the custom URL. ## Screenshots ![unknown](https://user-images.githubusercontent.com/17184363/37141178-e3a363ec-22bc-11e8-9749-07cb4d1de21c.png)
GiteaMirror added the type/question label 2025-11-02 04:06:24 -06:00
Author
Owner

@lafriks commented on GitHub (Mar 8, 2018):

Correct nginx config should be:

location /gitea {
     rewrite ^/gitea(/.*)$ $1 break;
     proxy_pass          http://localhost:3000;
     proxy_read_timeout  90;
     proxy_set_header Host $server_name;
     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;
}
@lafriks commented on GitHub (Mar 8, 2018): Correct nginx config should be: ``` location /gitea { rewrite ^/gitea(/.*)$ $1 break; proxy_pass http://localhost:3000; proxy_read_timeout 90; proxy_set_header Host $server_name; 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; } ```
Author
Owner

@lfdmn commented on GitHub (Mar 8, 2018):

Great thanks!

I only needed to add the trailing slash for the location otherwise I was getting error 404 after sign in page.

   location /gitea/ {
        rewrite ^/gitea(/.*)$ $1 break;
        proxy_pass          http://localhost:3000;
        proxy_read_timeout  90;
        proxy_set_header Host $server_name;
        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;
    }
@lfdmn commented on GitHub (Mar 8, 2018): Great thanks! I only needed to add the trailing slash for the location otherwise I was getting error 404 after sign in page. ``` location /gitea/ { rewrite ^/gitea(/.*)$ $1 break; proxy_pass http://localhost:3000; proxy_read_timeout 90; proxy_set_header Host $server_name; 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; } ```
Author
Owner

@gbip commented on GitHub (Mar 19, 2018):

I just had the same error with the same config.
I was able to solve my problem by looking at the nginx error logs :

2018/03/19 09:55:07 [crit] 45595#0: *3021 mkdir() "cache/proxy_temp/1/11" failed (13: Permission denied) while readintream: "http://127.0.0.1:3000/css/semantic-2.2.1.min.css", host: "git.mydomain.com"

Deleting /var/www/cache/proxy_temp solved the problem.

@gbip commented on GitHub (Mar 19, 2018): I just had the same error with the same config. I was able to solve my problem by looking at the nginx error logs : ``` 2018/03/19 09:55:07 [crit] 45595#0: *3021 mkdir() "cache/proxy_temp/1/11" failed (13: Permission denied) while readintream: "http://127.0.0.1:3000/css/semantic-2.2.1.min.css", host: "git.mydomain.com" ``` Deleting `/var/www/cache/proxy_temp` solved the problem.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#1606