Unable to resolve wasm / unityweb errors un runcloud nginx server - nginx

Site is hosted on a Ubuntu 18 server
Managed by runcloud.io
PHP 7.4
runcloud's nginx default config.
We have a webgl build deployed on our staging server, and unable to get it to load without throwing console errors:
You can reduce your startup time if you configure your web server to host .unityweb files using gzip compression.
wasm streaming compile failed: TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'.
falling back to ArrayBuffer instantiation
I have create the following nginx config file:
location ~ .(wasm)$ {
add_header Content-Encoding gzip;
add_header Content-Type application/wasm;
}
location ~ .(unityweb)$ {
add_header Content-Encoding gzip;
add_header Content-Type application/octet-stream;
}
location ~ .(data.unityweb)$ {
add_header Content-Encoding gzip;
add_header Content-Type application/octet-stream;
}
location ~ .(wasm.framework.unityweb)$ {
add_header Content-Encoding gzip;
add_header Content-Type application/octet-stream;
}
include /etc/nginx-rc/mime.types;
types {
application/wasm wasm;
}
default_type application/octet-stream;
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types application/wasm application/octet-stream text/plain text/css text/xml application/json application/javascript application/xml+rss application/atom+xml image/svg+xml;

I managed to host a Unity/WelGL app on a nginx server changing parameters of my Unity "Project Settings":
In "Player" tab, open "Publishing Settings":
Compression Format: Gzip
Decompression Fallback: ON
Found the solution on the Unity WebGL documentation. This is avoiding the error message.
I did not had to change my nginx configuration files.

Related

DDEV doesn't handle SVGZ-files in Nginx

I use DDEV v1.15.3 with Typo3 v9 environment. I created the Typo3 environment according to the Quick Guide with ddev config --project-type=typo3 --php-version 7.3 --docroot=public --create-docroot=true. So far everything works fine, but no SVGZ files are displayed.
A svgz file uploaded in the backend in the fileadmin is not displayed in the browser - like https://ddev-typo3v9.ddev.site:444/fileadmin/user_upload/meinen_jmd_vor_ort_finden.svgz. I get the following error message:
This page contains the following errors:
error on line 1 at column 1: Encoding error
Below is a rendering of the page up to the first error.
To enable compression with gzip in the nginx-container, I added the following lines to the file .ddev/nginx_full/nginx-site.conf
# Compression
gzip on;
gzip_proxied any;
gzip_comp_level 6; # Level of compression
gzip_http_version 1.1;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_types
text/plain
text/css
text/xml
application/x-javascript
application/atom+xml
text/mathml
text/vnd.sun.j2me.app-descriptor
text/vnd.wap.wml
text/x-component
text/javascript
application/javascript
application/json
application/xml
application/rss+xml
font/truetype
font/opentype
application/vnd.ms-fontobject
image/svg+xml svg svgz;
gzip_static on;
gunzip on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6] \."; # Disable for IE < 6
# Add a vary header for downstream proxies to avoid sending
# cached gzipped files to IE6
gzip_vary on;
# ### Compression ###
# For CSS with compression
location ~* "\.css(\.|\.\d{10}\.)gzip$" {
rewrite ^(.+css)\.(\d+\.)gzip$ /$1.gzip;
add_header Content-Encoding gzip;
add_header Vary Accept-Encoding;
add_header Access-Control-Allow-Origin *;
gzip off;
types { text/css gzip; }
expires max;
log_not_found off;
}
# For JavaScript with compression
location ~* "\.js(\.|\.\d{10}\.)gzip$" {
rewrite ^(.+js)\.(\d+\.)gzip$ /$1.gzip;
add_header Content-Encoding gzip;
add_header Vary Accept-Encoding;
gzip off;
default_type application/javascript;
expires max;
log_not_found off;
}
# Compression for SVGZ
location ~* \.svgz$ {
add_header Content-Encoding gzip;
}
When I use ddev ssh to connect to the docker container, the nginx configuration also contains the above lines.
Thanks for your help.
Best greetings
-- Gerald
What you need in .ddev/nginx_full/nginx-site.conf is adding
location ~ \.svgz$ { add_header Content-Encoding gzip; }
I put my nginx-site.conf file at https://gist.github.com/rfay/5071ff19237ee7b83442cd8ad0311459
I used the file example.svgz from https://www.online-convert.com/file-format/svgz
This nginx issue explained what to do.
Here's what I see after 1) Uploading example.svgz with the file manager and then 2) Clicking the "show" icon.
If you think this is important to add to the default nginx configurations, please open an issue or a PR at https://github.com/drud/ddev/issues

nginx not serving default mediagoblin on debian jessie

I have been trying to figure this out all weekend now... I have given up on googling. I have found similar issues but none of the solutions I find have resolved the issue. I'm very new to media goblin, and haven't really dived into linux this deep before, so I am very noobish.
I have followed the instructions from http://mediagoblin.readthedocs.io/en/stable/siteadmin/deploying.html keeping all the defaults, just to get the default setup to work. I figured from there I would be able to start changing things and see what happens. Okay enough of the intro.
When I input
nginx -t
I get
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
When I input
./lazyserver.sh --server-name=fcgi fcgi_host=127.0.0.1 fcgi_port=26543
I get
Using paster config: paste_local.ini
Using ./bin/paster
+ export CELERY_ALWAYS_EAGER=true
+ ./bin/paster serve paste_local.ini --server-name=fcgi fcgi_host=127.0.0.1 fcgi_port=26543 --reload
Starting subprocess with file monitor
2017-05-22 08:39:22,377 INFO [mediagoblin.app] GNU MediaGoblin 0.9.0 main server starting
2017-05-22 08:39:22,647 INFO [mediagoblin.app] Setting up plugins.
2017-05-22 08:39:22,648 INFO [mediagoblin.init.plugins] Importing plugin module: mediagoblin.plugins.geolocation
2017-05-22 08:39:22,648 INFO [mediagoblin.init.plugins] Importing plugin module: mediagoblin.plugins.basic_auth
2017-05-22 08:39:22,648 INFO [mediagoblin.init.plugins] Importing plugin module: mediagoblin.plugins.processing_info
2017-05-22 08:39:22,648 INFO [mediagoblin.init.plugins] Importing plugin module: mediagoblin.media_types.image
2017-05-22 08:39:22,797 INFO [mediagoblin.init.celery] Setting celery configuration from object "mediagoblin.init.celery.dummy_settings_module"
Starting server in PID 990.
It doesn't appear as though the server is being served. When I go to the server ip i get the default nginx page.
my /etc/nginx/nginx.conf file is as follows
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
My /etc/nginx/sites-enabled/nginx.conf is as follows
server {
#################################################
# Stock useful config options, but ignore them :)
#################################################
include /etc/nginx/mime.types;
autoindex off;
default_type application/octet-stream;
sendfile on;
# Gzip
gzip on;
gzip_min_length 1024;
gzip_buffers 4 32k;
gzip_types text/plain application/x-javascript text/javascript text/xml text/css;
#####################################
# Mounting MediaGoblin stuff
# This is the section you should read
#####################################
# Change this to update the upload size limit for your users
client_max_body_size 8m;
# prevent attacks (someone uploading a .txt file that the browser
# interprets as an HTML file, etc.)
add_header X-Content-Type-Options nosniff;
server_name mediagoblin.example.org www.mediagoblin.example.org;
access_log /var/log/nginx/mediagoblin.example.access.log;
error_log /var/log/nginx/mediagoblin.example.error.log;
# MediaGoblin's stock static files: CSS, JS, etc.
location /mgoblin_static/ {
alias /srv/mediagoblin.example.org/mediagoblin/mediagoblin/static/;
}
# Instance specific media:
location /mgoblin_media/ {
alias /srv/mediagoblin.example.org/mediagoblin/user_dev/media/public/;
}
# Theme static files (usually symlinked in)
location /theme_static/ {
alias /srv/mediagoblin.example.org/mediagoblin/user_dev/theme_static/;
}
# Plugin static files (usually symlinked in)
location /plugin_static/ {
alias /srv/mediagoblin.example.org/mediagoblin/user_dev/plugin_static/;
}
# Mounting MediaGoblin itself via FastCGI.
location / {
fastcgi_pass 127.0.0.1:26543;
include /etc/nginx/fastcgi_params;
# our understanding vs nginx's handling of script_name vs
# path_info don't match :)
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param SCRIPT_NAME "";
}
}
Any advice would be greatly appreciated.
Edit 1
Response from running
./lazyserver.sh --server-name=fcgi fcgi_host=127.0.0.1 fcgi_port=26543
is still
Using paster config: paste_local.ini
Using ./bin/paster
+ export CELERY_ALWAYS_EAGER=true
+ ./bin/paster serve paste_local.ini --server-name=fcgi fcgi_host=127.0.0.1 fcgi_port=26543 --reload
Starting subprocess with file monitor
2017-05-22 12:06:37,345 INFO [mediagoblin.app] GNU MediaGoblin 0.9.0 main server starting
2017-05-22 12:06:37,583 INFO [mediagoblin.app] Setting up plugins.
2017-05-22 12:06:37,584 INFO [mediagoblin.init.plugins] Importing plugin module: mediagoblin.plugins.geolocation
2017-05-22 12:06:37,584 INFO [mediagoblin.init.plugins] Importing plugin module: mediagoblin.plugins.basic_auth
2017-05-22 12:06:37,584 INFO [mediagoblin.init.plugins] Importing plugin module: mediagoblin.plugins.processing_info
2017-05-22 12:06:37,585 INFO [mediagoblin.init.plugins] Importing plugin module: mediagoblin.media_types.image
2017-05-22 12:06:37,714 INFO [mediagoblin.init.celery] Setting celery configuration from object "mediagoblin.init.celery.dummy_settings_module"
Starting server in PID 976.
current mediagoblin nginx.conf:
server {
#################################################
# Stock useful config options, but ignore them :)
#################################################
include /etc/nginx/mime.types;
autoindex off;
default_type application/octet-stream;
sendfile on;
# Gzip
gzip on;
gzip_min_length 1024;
gzip_buffers 4 32k;
gzip_types text/plain application/x-javascript text/javascript text/xml text/css;
listen 80;
server_name 10.1.1.74;
#####################################
# Mounting MediaGoblin stuff
# This is the section you should read
#####################################
# Change this to update the upload size limit for your users
client_max_body_size 8m;
# prevent attacks (someone uploading a .txt file that the browser
# interprets as an HTML file, etc.)
add_header X-Content-Type-Options nosniff;
server_name mediagoblin.example.org www.mediagoblin.example.org;
access_log /var/log/nginx/mediagoblin.example.access.log;
error_log /var/log/nginx/mediagoblin.example.error.log;
# MediaGoblin's stock static files: CSS, JS, etc.
location /mgoblin_static/ {
alias /srv/mediagoblin.example.org/mediagoblin/mediagoblin/static/;
}
# Instance specific media:
location /mgoblin_media/ {
alias /srv/mediagoblin.example.org/mediagoblin/user_dev/media/public/;
}
# Theme static files (usually symlinked in)
location /theme_static/ {
alias /srv/mediagoblin.example.org/mediagoblin/user_dev/theme_static/;
}
# Plugin static files (usually symlinked in)
location /plugin_static/ {
alias /srv/mediagoblin.example.org/mediagoblin/user_dev/plugin_static/;
}
# Mounting MediaGoblin itself via FastCGI.
location / {
fastcgi_pass 127.0.0.1:26543;
include /etc/nginx/fastcgi_params;
# our understanding vs nginx's handling of script_name vs
# path_info don't match :)
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param SCRIPT_NAME "";
}
}
current /etc/nginx/nginx.conf:
Edit 2
Current nginx.conf file for server (both defaults are working)
server {
#################################################
# Stock useful config options, but ignore them :)
#################################################
include /etc/nginx/mime.types;
autoindex off;
default_type application/octet-stream;
sendfile on;
# Gzip
gzip on;
gzip_min_length 1024;
gzip_buffers 4 32k;
gzip_types text/plain application/x-javascript text/javascript text/xml text/css;
listen 80;
server_name 10.0.0.192;
#####################################
# Mounting MediaGoblin stuff
# This is the section you should read
#####################################
# Change this to update the upload size limit for your users
client_max_body_size 8m;
# prevent attacks (someone uploading a .txt file that the browser
# interprets as an HTML file, etc.)
add_header X-Content-Type-Options nosniff;
server_name mediagoblin.example.org www.mediagoblin.example.org;
access_log /var/log/nginx/mediagoblin.example.access.log;
error_log /var/log/nginx/mediagoblin.example.error.log;
# MediaGoblin's stock static files: CSS, JS, etc.
location /mgoblin_static/ {
alias /srv/mediagoblin.example.org/mediagoblin/mediagoblin/static/;
}
# Instance specific media:
location /mgoblin_media/ {
alias /srv/mediagoblin.example.org/mediagoblin/user_dev/media/public/;
}
# Theme static files (usually symlinked in)
location /theme_static/ {
alias /srv/mediagoblin.example.org/mediagoblin/user_dev/theme_static/;
}
# Plugin static files (usually symlinked in)
location /plugin_static/ {
alias /srv/mediagoblin.example.org/mediagoblin/user_dev/plugin_static/;
}
# Mounting MediaGoblin itself via FastCGI.
location / {
fastcgi_pass 10.0.0.192:26543;
include /etc/nginx/fastcgi_params;
# our understanding vs nginx's handling of script_name vs
# path_info don't match :)
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param SCRIPT_NAME "";
}
}
When I run this command, as suggested by the guide, I am unable to load the page.
./lazyserver.sh --server-name=fcgi fcgi_host=127.0.0.1 fcgi_port=26543
However when I run this command, it works.
./lazyserver.sh --server-name=fcgi fcgi_host=10.0.0.192 fcgi_port=26543
I'm not sure if the first one, as supplemented by the guide, implied that you were accessing it locally... which would make sense since the dns url created in the directions was supposed to work without implicitly creating a dns entry anywhere... orrr if i'm still doing something wrong.
You probably have a default server in /etc/nginx/sites-enabled/. If you use mediagoblin.example.org to access the server, then your server configuration will match.
You state that you use the server's IP address, which means that the default server will be used instead.
You have a number of options:
You could add the IP address to the server_name directive and pretend that that is a valid name for your server.
You could set up DNS or hosts so that you can use the correct name.
You could remove the other configuration file, so that this configuration becomes the de-facto default server.
See this document for more.

Nginx enable gzip

I want enable the gzip compression on my nginx server. The nginx.conf file is here:
http {
# Enable Gzip
server {
location ~* \.(?:ico|woff|css|js|gif|jpe?g|png)$ {
expires 30d;
add_header Pragma public;
add_header Cache-Control "public";
}
location /api {
try_files $uri $uri/ /api/index.php;
}
location / { ##merge
gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_proxied any;
gzip_types
# text/html is always compressed by HttpGzipModule
text/css
text/javascript
text/xml
text/plain
text/x-component
application/javascript
application/json
application/xml
application/rss+xml
font/truetype
font/opentype
application/vnd.ms-fontobject
image/svg+xml;
gzip_static on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { add_header "" ""; }
location ~ "^/ngx_pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon" { }
}
}
Unfortunately the gzip compression not working, Google Pagespeed and Gtmetrix not detect this.
Where can I place the gzip conf?
In The http{} server{} or location{} tag?
I already tried in the http and in the location tags too
You can put the gzip configuration anywhere, but if you want to apply it to all websites / files it is best to put it in the http section - this will then be the default for all server and location blocks. I would also "shorten" / change your config to the following:
http {
gzip on;
gzip_min_length 500;
gzip_proxied any;
gzip_comp_level 4;
gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/json application/xml application/rss+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml;
gzip_vary on;
gzip_disable "msie6";
... here come your server blocks / rest of your config
}
I use that configuration and it works fine for me - you can also test it in your browser first (for example with Firebug) before testing it with external services.
Using gzip_static only makes sense if you actually generate gzipped files for Nginx (as filename + .gz), so this has nothing to do with enabling gzip and should only be a possible second step.

Nginx default content-type

I would like NGINX send the content-type application/xml
for all response of a location:
My configuration is base on the documentation http://wiki.nginx.org/HttpCoreModule#types :
server {
server_name my_name
listen 8088;
keepalive_timeout 5;
location / {
proxy_pass http://myhost;
types { }
default_type application/xml
}
}
But the server always send as content-type "text/xml".
Any idea?

Nginx Reverse Proxy SSL / Minification

I am trying to use NginX as a reverse proxy for a few IIS Servers. The goal is to have NginX sit in from of the IIS / Apache servers caching static items such as CSS / JS / Images. I am also trying to get NginX to automatically minify js / css files using its perl module.
I found a sample script for minification here:
http://petermolnar.eu/linux-tech-coding/nginx-perl-minify-css-js/
With the scrip everything works fine, except the reverse proxy breaks.
Questions:
Is what i am trying to accomplish even possible? I want NginX to first minify the scripts before saving them to cache.
Can nginX automtically set the proper expires headers so that static items are cached as long as possible, and only replaced when querystrings are changed (jquery.js?timestamp=march-2012)
Can NginX GZIP the resources before sending them out.
Can NGinx Forward requests or serve up a "Down For Maintenance page" if it cannot connec to back end server.
Any help would be greatly appreciated.
Here is what i have in my sites-enabled/default so far.
server {
location / {
proxy_pass http://mywebsite.com;
proxy_set_header Host $host;
proxy_cache STATIC;
proxy_cache_valid 200 1d;
proxy_cache_use_stale error timeout invalid_header updating
http_500 http_502 http_503 http_504;
}
location #minify {
perl Minify::minify_handler;
}
location ~ \.css$ {
try_files $uri.min.css #minify;
}
location /*.js {
expires 30d;
}
}
Nginx is the ideal solution for reverse-proxy, it's also Unix way "do one thing and do it well". So I'd advice you to split content serve and minification process out instead of using third-party plugins to do many things at once.
Best practice is to do minify&obfuscate phase on local system before you do a deployment on production, this is easy to say and not hard to do, see the google way to compress static assets. Once you got assets ready-to-use, we can setup nginx configuration.
Answers:
use minify&obfuscate before deploy it on production
you can find assets by regexp (directory name or file extension)
location ~ ^/(assets|images|javascripts|stylesheets|swfs|system)/ {
gzip_static on;
expires max;
add_header Cache-Control public;
add_header Last-Modified "";
add_header ETag "";
break;
}
use gzip on and gzip_static on to serve gzipped files instead of compress it every time when request is coming.
use try_files to detect the maintenance page exists or not
try_files $uri /system/maintenance.html #mywebsite;
if (-f $document_root/system/maintenance.html) {
return 503;
}
See the full nginx config for your case:
http {
keepalive_timeout 70;
gzip on;
gzip_http_version 1.1;
gzip_disable "msie6";
gzip_vary on;
gzip_min_length 1100;
gzip_buffers 64 8k;
gzip_comp_level 3;
gzip_proxied any;
gzip_types text/plain text/css application/x-javascript text/xml application/xml;
upstream mywebsite {
server 192.168.0.1 # change it with your setting
}
server {
try_files $uri /system/maintenance.html #mywebsite;
location #mywebsite {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://mywebsite;
}
location ~ ^/(assets|images|javascripts|stylesheets|swfs|system)/ {
gzip_static on;
expires max;
add_header Cache-Control public;
add_header Last-Modified "";
add_header ETag "";
break;
}
if (-f $document_root/system/maintenance.html) {
return 503;
}
location #503 {
error_page 405 = /system/maintenance.html;
if (-f $document_root/system/maintenance.html) {
rewrite ^(.*)$ /system/maintenance.html break;
}
rewrite ^(.*)$ /503.html break;
}
}
}

Resources