Getting a 404 on Nginx RTMP Module stats file - xslt

I'm not understanding why I get a 404 when I set up my stats view in Nginx RTMP Module.
The instructions I'm following are fairly straightforward and especially here.
I'm using a Ubuntu VM on Google Cloud.
I've placed my stat.xsl file in /var/www/html
That is the default location for Nginx assets, as specified in sites-enabled/default folder:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
And here is the snippet I copy/pasted and adapted in my nginx.conf:
server{
listen 80;
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
# you can move stat.xsl to a different location
# under linux you could use /var/user/www for example
root html;
}
}
The goal here is to be able to type [my-ip-address/stat and get the formatted xsl content.
There's something here I'm not getting -any help please?

Have you tried typing /statOR instead?
server {
listen 80;
server_name localhost;
# rtmp statistics
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
# you can move stat.xsl to a different location
# under linux you could use /var/user/www for example
root html;

Related

How to use a block for all non-root paths in nginx config? [duplicate]

My server listen 443 port and redirects the requests to another port in the server. Also my server listen 80 port and displays a static content the user when they browse http://www.xxxx.com
But I want also to display static content when user browse https://www.xxxx.com
How can I manage this ? My Nginx config file is ;
server {
listen 443 ssl;
server_name xxxx.com;
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
location / {
expires off;
proxy_pass http://backend;
}
}
server {
listen 80;
listen [::]:80;
server_name xxxx.com;
root /var/www/xxxx.com/html;
index index.html;
location / {
try_files $uri $uri/=404;
}
}
I want to display my index.html file when user browse my website with https://www.xxxx.com and my proxy will continue to work at backend
You can invoke a named location as the default action of your try_files statement.
For example:
location / {
try_files $uri $uri/ #proxy;
}
location #proxy {
proxy_pass http://backend;
}
See this document for details.

ELB transferring to wordpress with Nginx on EC2 shows 404

※ I'm using example.com as example
I'm developing an app with ELB and EC2.
The structure is as followed.
When an user access to /manage/*, ELB will transfer to wordpress hosted instance.
Here is the ELB setting.
About ELB it works, but after transfered to wordpress side, CSS and JS files' response show 404.
When I access to /magazine/* URL, loading animation of wordpress theme starts to work but get stuck because of not loaded css and js.
I'm guessing it's because of nginx configuration but can't solve it.
This is the content of configuration file. I just add /etc/nginx/conf.d/vhosts.conf and write some settings. I don't touch other files.
# vhosts.conf
server {
listen 80;
server_name example.com;
return 301 https://$host$request_uri;
}
server {
listen 443;
server_name example.com;
root /var/www/html;
location /magazine {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
below /var/www/html, project's structure is as followed.
/wp-content
/wp-admin
/wp-include
index.php
wp-config.php
for other information,
I installed php-fpm.
SSL certification is set up with ACM and Route53
Additional Info
Both siteurl and home in DB table wp_options are set to https://example.com/magazine.
Result
made /var/www/html/magazine directory and move all files into it.
server {
listen 80;
server_name example.com;
return 301 https://$host$request_uri;
}
server {
listen 443;
server_name example.com;
location ~* /(wp-config|xmlrpc)\.php {
deny all;
}
location #magazine {
rewrite ^/magazine(.*) /magazine/index.php?$args;
}
location ^~ /magazine {
root /var/www/html;
index index.php index.html index.htm;
try_files $uri $uri/ #magazine;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
}
}
Since you are not serving wordpress from the root of your url, you must tell wordpress to load the assets from the subdirectory. How you can do this, is described in a wordpress support article. [1]
Did you check whether the WP_HOME and WP_SITEURL variables are set correctly?
Could you edit your question and include the URL your browser tries to load for the css and js files since it is not fully visible in the screenshot?
Edit:
Thanks to the additional information we know that wordpress constructs the path as expected. So, now I share your opinion that nginx is causing the issue.
I looked around and noticed two possible issues with the nginx configuration:
The root statement should probably be inside the location block. I do not know if this is really necessary, but many people do it. [2]
The location block does a prefix match and includes the prefix magazine into the $uri variable as stated in a serverfault thread. [3]
You could strip away the prefix by using a regex as follows:
location ~ ^/magazine(.*) {
root /var/www/html;
try_files $1 $1/ /index.php?$args;
}
Note: I do not know if the directory redirect $1 and default redirect to /index.php?$args make sense for serving js/css assets. You should probably remove them if they are not necessary.
References
[1] https://wordpress.org/support/article/changing-the-site-url/#changing-the-site-url
[2] https://serverfault.com/a/258540/531099
[3] https://serverfault.com/a/455853/531099

Nginx not serving files from /var/www/html after deploying Django app

I have a Django application stored at /var/www/w_gm .
Now I have used Nginx + Gunicorn to deploy it.
My default conf file at
root#dev:/etc/nginx/sites-enabled# ls
default w_gm
Default conf file :
server {
listen 80 default_server;
listen [::]:80 ipv6only=on default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php7.0-cgi alone:
#fastcgi_pass 127.0.0.1:9000;
# With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
w_gm conf file :
server {
listen 80;
server_name 119.00.00.100;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /var/www/w_gm/w_gm/;
}
location / {
include proxy_params;
proxy_pass http://unix:/var/www/w_gm/w_gm.sock;
}
}
Now the issue is that, when am tying in my IP address i.e, it's redirecting me to the Django app and it's working perfectly fine. But my other files which are in var/www/html doesn't get served i.e if I have <ip.addr>/work1 , it gives me error.
Now if I edit the w_gm conf file and add a suffix, let's say server_name 119.00.00.100/abc; , which obviously is wrong, my /var/www/html files start working.
I need a solution where if I type in <ip.addr>/something, then it should redirect to Django app, else serve the files which are in var/www/html.
You currently have two servers, but it sounds like you only want one server.
<ip.addr>/something is ambiguous, so you need Nginx to look for files in one root and send requests to the proxy only if they are not found.
You would need to combine your two server blocks into something like this:
root /var/www/html;
location / {
try_files $uri $uri/ #proxy;
}
location ~ \.php$ {
...
}
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /var/www/w_gm/w_gm/;
}
location #proxy {
include proxy_params;
proxy_pass http://unix:/var/www/w_gm/w_gm.sock;
}
This assumes that the /static/ URI is unambiguous, and that no URIs ending with .php are sent to the proxy. See this docuemnt for more.

How to confingure nginx for domain and subdomain on AWS with ubuntu

I want to configure nginx for domain as well as sub domain on ubuntu as follows
mysite.in pointing to website
demo.mysite.in pointing to demo project
uat.mysite.in pointing to test project
My nginx conf looks like:
server {
listen 80 defaultserver;
listen [::]:80 defaultserver ipv6only=on;
server_name mysite.in;
location / {
root /home/amita/Website/website-v1;
try_files $uri$args $uri$args/ $uri $uri/ /index.html =404;
}
}
server {
listen 8087;
listen [::]:8087 default_server ipv6only=on;
server_name demo.mysite.in;
location / {
root /home/amita/Project/frontend/demo/project/dist;
try_files $uri$args $uri$args/ $uri $uri/ /index.html =404;
}
}
server {
listen 8088;
listen [::]:8088 default_server ipv6only=on;
server_name test.mysite.in;
location / {
root /home/amita/Project/frontend/test/project/dist;
try_files $uri$args $uri$args/ $uri $uri/ /index.html =404;
}
}
mysite.in , demo.mysite.in, test.mysite.in all shows up webiste.
I am unable to rectify mistake. Please help !!
You misspelled default_server in the first server block. The directive default_server applied to a server block means this server will respond to any request for which no specific server has been found to respond. It is commonly used in virtual hosting configurations.
You can also run nginx -t every time you edit your configuration to check if there are any new errors.

Nginx including conf from conf.d but still loading default settings

All configurations are being included and conf test is passed too. But Nginx is still serving the default HTML from /usr/share/nginx/html, instead of location root from conf file in conf.d directory.
conf file from conf.d directory
upstream django {
server unix:///tmp/server.sock;
}
server {
listen 80;
server_name server.test.com;
access_log /srv/source/logs/access-nginx.log;
error_log /srv/source/logs/error-nginx.log;
location / {
uwsgi_pass django;
include /srv/source/conf/uwsgi/params;
}
location /static/ {
root /srv/source/;
index index.html index.htm;
}
location /media/ {
root /srv/source/media/;
index index.html index.htm;
}
# alias favicon.* to static
location ~ ^/favicon.(\w*)$ {
alias /srv/source/static/favicon.$1;
}
}
The default nginx config is in /etc/nginx/nginx.conf. By default that file includes the following lines (at least that is the case on rhel based and arch based distros):
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
Thanks to the root in the server section nginx will keep serving the files under that directory until you comment our these lines. This happens just after conf.d is loaded (as noted in the snippet above).
No matter what you change inside conf.d that last part of the file will still be loaded. Since it is that file (/etc/nginx/nginx.conf) that loads the configs in conf.d.
And yes, you definitely should comment out that default server if you plan to use nginx.