plumn 0 Posted November 6, 2020 Posted November 6, 2020 (edited) server { listen 80; server_name blog.my.domain www.blog.my.domain; return 301 https://blog.my.domain$request_uri; } server { listen 443 ssl http2; server_name www.blog.my.domain; return 301 https://blog.my.domain$request_uri; } server { listen 80; listen [::]:80 default_server; root /home/wwwroot/my.domain; index index.html index.htm index.php; #charset koi8-r; access_log /var/log/nginx/my.domain.access.log main; listen 443 ssl http2 default_server; ssl_certificate "/usr/local/cert/my_domain.crt"; ssl_certificate_key "/usr/local/cert/my_domain.key"; ssl_session_timeout 10m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_prefer_server_ciphers on; client_max_body_size 1024m; error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location /emby { return 302 $scheme://$host/emby/; } location /emby/ { # Proxy main Emby traffic # The / at the end is significant. proxy_pass http://127.0.0.1:8096/; proxy_pass_request_headers on; 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; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; # Disable buffering when the nginx proxy gets very resource heavy upon streaming proxy_buffering off; } location ~ \.php { fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } location ~ ^.+\.php { fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; } location = /config.inc.php { deny all; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 15d; } location ~ .*\.(js|css)?$ { expires 1d; } } Hello , everyone , I'm new here and have a difficult problem with me , I checked many discussion here and google , I want achieve visiting my blog domain : blog.my.domain/emby to reach my emby server which behind nginx reserve proxy . My emby setting is default port , intranet http port 8096 and https port 8920 , no internet visit . When I vist blog.my.domain/emby , it jump to https://blog.my.domain/emby/web/index.html , only get a pure black background , I use F12 to check find some 404 not found errors with logowhite.png , apploader.js , images/icon-144x144.png ,familar errors like this thread : https://emby.media/community/index.php?/topic/80952-nginx-reverse-proxy-config-for-emby-website-with-ssl/ I don't know much about how nginx grammar works , if anybody help me to check how to fix this problem ? Many thanks ! Circumstance: Centos 7 kernel-ml-5.9.5-1.el7.elrepo.x86_64 AWS VPS PHP 7.2.34 (cli) (built: Oct 1 2020 13:37:37) ( NTS ) Edited November 6, 2020 by plumn
Luke 42085 Posted November 6, 2020 Posted November 6, 2020 Hi, I would suggest comparing your nginx configuration to that of @pir8radio.
plumn 0 Posted November 6, 2020 Author Posted November 6, 2020 2 minutes ago, Luke said: Hi, I would suggest comparing your nginx configuration to that of @pir8radio. Thank you for your quick reply , yeah I checked pir8radio config about emby.my.domain with location / {} and other nice suggestion ,such as http://www.mydomain.com:8096/ , I also notice some config about https://www.mydomain.com/emby/ ,that's what I want realised , but in the monment I don't find pir8radio's suggestion with this .
pir8radio 1312 Posted November 6, 2020 Posted November 6, 2020 (edited) 3 hours ago, plumn said: Thank you for your quick reply , yeah I checked pir8radio config about emby.my.domain with location / {} and other nice suggestion ,such as http://www.mydomain.com:8096/ , I also notice some config about https://www.mydomain.com/emby/ ,that's what I want realised , but in the monment I don't find pir8radio's suggestion with this . in your locations you are only addressing calls to /emby/ not all of emby's files are located there. like CSS files, they are located at /web/ even though emby "should" handle requests with or without /emby its always best to just get rid of it if emby didnt ask for it in the first place. you need to do a rewrite if you want to use a sub directory like domain.com/XXXX its not advised you will usually always have some weird thing that is broken using sub directory.. sub domain is prefered XXXX.domain.com But try this: get rid of this: location /emby { return 302 $scheme://$host/emby/; } location /emby/ { # Proxy main Emby traffic # The / at the end is significant. proxy_pass http://127.0.0.1:8096/; proxy_pass_request_headers on; 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; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; # Disable buffering when the nginx proxy gets very resource heavy upon streaming proxy_buffering off; } add in this: location /emby { rewrite /emby/(.*) /$1 break; proxy_pass http://127.0.0.1:8096; proxy_redirect off; proxy_pass_request_headers on; 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; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; # Disable buffering when the nginx proxy gets very resource heavy upon streaming proxy_buffering off; } Be careful with your slashes (/) do some googleing they totally change how nginx handles the url... You had slash after 8096 in your config and had one after emby in your location "/emby/" so make sure you put it in how it is above in my example... I used your header settings so I didn't test it, but should work. let us know. Edited November 6, 2020 by pir8radio
plumn 0 Posted November 7, 2020 Author Posted November 7, 2020 (edited) 9 hours ago, pir8radio said: in your locations you are only addressing calls to /emby/ not all of emby's files are located there. like CSS files, they are located at /web/ even though emby "should" handle requests with or without /emby its always best to just get rid of it if emby didnt ask for it in the first place. you need to do a rewrite if you want to use a sub directory like domain.com/XXXX its not advised you will usually always have some weird thing that is broken using sub directory.. sub domain is prefered XXXX.domain.com But try this: get rid of this: location /emby { return 302 $scheme://$host/emby/; } location /emby/ { # Proxy main Emby traffic # The / at the end is significant. proxy_pass http://127.0.0.1:8096/; proxy_pass_request_headers on; 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; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; # Disable buffering when the nginx proxy gets very resource heavy upon streaming proxy_buffering off; } add in this: location /emby { rewrite /emby/(.*) /$1 break; proxy_pass http://127.0.0.1:8096; proxy_redirect off; proxy_pass_request_headers on; 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; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; # Disable buffering when the nginx proxy gets very resource heavy upon streaming proxy_buffering off; } Be careful with your slashes (/) do some googleing they totally change how nginx handles the url... You had slash after 8096 in your config and had one after emby in your location "/emby/" so make sure you put it in how it is above in my example... I used your header settings so I didn't test it, but should work. let us know. Yeah , I know sub.my.domain is a better way , thank you for your advice . Just wondering why my.domain/sub can't work .I noticed your new config and tried it before and now try again , but it's same 404 wrong with those CSS files not found . (.*) match ALL path behind /emby/ , then $1 select region 1 which mean url after /emby/ for example web/index.html from my.domain/emby/web/index.html ,and proxy it ,combine with location /emby , whole link will come to /emby +/+web/index.html , so theoretically when I visit my.domain/emby , it should jump into my.domain/emby/web/index.html , yeah , this jump works like my config , but errors come out the same result , only the black background successful loaded , no CSS such as .js & pngs. P.S. Here are some access logs from nginx : [root@]# tail -f /var/log/nginx/my.domain.access.log - - [07/Nov/2020:11:05:01 ] "GET /emby/ HTTP/2.0" 302 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36 Edg/86.0.622.63" "-" - - [07/Nov/2020:11:05:01 ] "GET /emby/web/index.html HTTP/2.0" 200 2863 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36 Edg/86.0.622.63" "-" - - [07/Nov/2020:11:05:02 ] "GET /emby/web/apploader.js?v=4.5.2.0 HTTP/2.0" 404 555 "https://my.domain/emby/web/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36 Edg/86.0.622.63" "-" - - [07/Nov/2020:11:05:02 ] "GET /emby/web/modules/themes/logowhite.png HTTP/2.0" 404 555 "https://my.domain/emby/web/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36 Edg/86.0.622.63" "-" - - [07/Nov/2020:11:05:02 ] "GET /emby/web/manifest.json HTTP/2.0" 304 0 "https://my.domain/emby/web/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36 Edg/86.0.622.63" "-" - - [07/Nov/2020:11:43:12 ] "GET /emby/web/index.html HTTP/2.0" 200 2863 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36 Edg/86.0.622.63" "-" - - [07/Nov/2020:11:43:12 ] "GET /emby/web/apploader.js?v=4.5.2.0 HTTP/2.0" 404 555 "https://my.domain/emby/web/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36 Edg/86.0.622.63" "-" - - [07/Nov/2020:11:43:12 ] "GET /emby/web/modules/themes/logowhite.png HTTP/2.0" 404 555 "https://my.domain/emby/web/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36 Edg/86.0.622.63" "-" - - [07/Nov/2020:11:43:13 ] "GET /emby/web/favicon.ico HTTP/2.0" 200 49334 "https://my.domain/emby/web/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36 Edg/86.0.622.63" "-" - - [07/Nov/2020:11:43:13 ] "GET /emby/web/manifest.json HTTP/2.0" 304 0 "https://my.domain/emby/web/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36 Edg/86.0.622.63" "-" Edited November 7, 2020 by plumn
plumn 0 Posted November 7, 2020 Author Posted November 7, 2020 11 hours ago, pir8radio said: in your locations you are only addressing calls to /emby/ not all of emby's files are located there. like CSS files, they are located at /web/ even though emby "should" handle requests with or without /emby its always best to just get rid of it if emby didnt ask for it in the first place. you need to do a rewrite if you want to use a sub directory like domain.com/XXXX its not advised you will usually always have some weird thing that is broken using sub directory.. sub domain is prefered XXXX.domain.com But try this: get rid of this: location /emby { return 302 $scheme://$host/emby/; } location /emby/ { # Proxy main Emby traffic # The / at the end is significant. proxy_pass http://127.0.0.1:8096/; proxy_pass_request_headers on; 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; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; # Disable buffering when the nginx proxy gets very resource heavy upon streaming proxy_buffering off; } add in this: location /emby { rewrite /emby/(.*) /$1 break; proxy_pass http://127.0.0.1:8096; proxy_redirect off; proxy_pass_request_headers on; 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; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; # Disable buffering when the nginx proxy gets very resource heavy upon streaming proxy_buffering off; } Be careful with your slashes (/) do some googleing they totally change how nginx handles the url... You had slash after 8096 in your config and had one after emby in your location "/emby/" so make sure you put it in how it is above in my example... I used your header settings so I didn't test it, but should work. let us know. Finnally I made it , thank you and @Luke , with the help of this article : https://serverfault.com/questions/796930/nginx-is-giving-404-errors-on-all-but-the-html-pages I take the 3rd method , check all the static files from /emby/ path and use a 417 error page redirect , not easy for me , maybe a bit ugly , but all works fine now server { listen 80; server_name blog.my.domain www. blog.my.domain; return 301 https:// blog.my.domain$request_uri; } server { listen 443 ssl http2; server_name www. blog.my.domain; return 301 https:// blog.my.domain$request_uri; } server { listen 80; listen [::]:80 default_server; root /home/wwwroot/my.domain; index index.html index.htm index.php; #charset koi8-r; access_log /var/log/nginx/my.domain.access.log main; listen 443 ssl http2 default_server; ssl_certificate "/usr/local/cert/my_domain.crt"; ssl_certificate_key "/usr/local/cert/my_domain.key"; ssl_session_timeout 10m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_prefer_server_ciphers on; client_max_body_size 1024m; error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~* ^/(js|css|jpg|jpeg|gif|png|ico|pdf|txt)/.+\.(js|css|jpg|jpeg|gif|png|ico|pdf|txt)$ { #checking if referer is from emby ,not disturb my blog path static files loading. if ($http_referer ~ "^.*/emby/") { return 417; } } error_page 417 /emby/$request_uri; location ^~ /emby/ { proxy_pass http://127.0.0.1:8096/; proxy_pass_request_headers on; 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; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; # Disable buffering when the nginx proxy gets very resource heavy upon streaming proxy_buffering off; } location / { index index.html index.php; if (-f $request_filename/index.html) { rewrite (.*) $1/index.html break; } if (-f $request_filename/index.php) { rewrite (.*) $1/index.php; } if (!-f $request_filename) { rewrite (.*) /index.php; } } location ~ \.php { fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } location ~ ^.+\.php { fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; } location ~ /.ht { deny all; } location = /config.inc.php { deny all; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 15d; } location ~ .*\.(js|css)?$ { expires 1d; } }
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now