Plone and nginx configuration does not return any apparent results - plone

I'm trying to configure nginx to run with plone, but I'm not having success.I don't get any errors when testing nginx with "/etc/init.d/nginx configtest" after creating my mysite.conf file, I restart nginx so that it can pick up the changes and I also don't get any errors,but the moment I type the URL configured in the browser, no content or message is displayed. Does anyone know what may be happening?
My configuration file is below:
upstream plone {
#define grupo de servidores que podem ser acessados
server 127.0.0.1:8080;
server ---.--.--.--:8080;
}
server {
listen 80;
server_name www.mysite.com;
access_log /var/log/nginx/mysite.com.access.log;
error_log /var/log/nginx/mysite.com.error.log;
location / {
rewrite ^/(.*)$ /VirtualHostBase/http/www.mysite.com:80/teste/VirtualHostRoot/$1 break;
proxy_pass http://localhost:8080;
#proxy_pass http://plone/VirtualHostBase/http/localhost:8080/teste/VirtualHostRoot/;
}
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name mysite.com;
rewrite ^/(.*) http:/mysite.com/$1 permanent;
}

Related

Nginx subdomain configuration Letsencryt wildcard HTTPS certificate

What I want to do ?
I have two application on local ports and I want to access them like that :
maindomain.com -> node.js app
sub.maindomain.com -> .net core app
My DNS config
maindomain.com (A Record) 11.111.11.111
sub.maindomain.com (A Record) 11.111.11.111
Nginx config
/etc/nginx/sites-enabled/maindomain.com (linked from ./sites-available/)
upstream node_app{
# node.js running
server 127.0.0.1:8000;
}
server{
listen 80;
server_name www.maindomain.com maindomain.com;
#Redirige toutes les requĂȘtes http vers https
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/maindomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/maindomain.com/privkey.pem;
server_name www.maindomain.com maindomain.com;
location / {
include proxy_params;
proxy_pass http://node_app;
}
}
/etc/nginx/sites-enabled/sub.maindomain.com (linked from /sites-available/)
upstream core_api{
# Asp.net core API running in background
server 127.0.0.1:5000;
}
server{
listen 80;
server_name www.sub.maindomain.com sub.maindomain.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/maindomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/maindomain.com/privkey.pem;
server_name www.sub.maindomain.com sub.maindomain.com;
location / {
include proxy_params;
proxy_pass http://core_api;
}
}
Result :
After that, I have restarted my nginx service.
Requests on sub.maindomain.com just redirect on maindomain.com.
What did I missed ?
Well it looks like you forgot:
server_name www.api-accropolis.maindomain.com api-accropolis.maindomain.com;
... in SSL server in /etc/nginx/sites-enabled/sub.maindomain.com
And you also forgot:
server_name www.maindomain.com maindomain.com;
... in SSL server in /etc/nginx/sites-enabled/maindomain.fr

Nginx reverse proxy for grafana using dashboard as subpath

I would like to use dashboard as my nginx location for my grafana install.
The problems is grafana uses dashboard in some of it url's like https://example.com/grafana/dashboard/new?orgId=1, where I would like it to be https://example.com/dashboard/dashboard/new?orgId=1 and I think my nginx location is rewriting to https://example.com/dashboard/new?orgId=1.
When I have it setup to use grafana as the subpath it all work as expected;
grafana.ini:
[server]
http_addr = 127.0.0.1
domain = example.com
root_url = %(protocol)s://%(domain)s/grafana/
nginx config:
# Upstream Servers
upstream grafana_server {
server localhost:3000;
}
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
include snippets/ssl-example.com.conf;
include snippets/ssl-params.conf;
root /var/www/example.com/html;
index index.html index.htm;
server_name example.com www.example.com;
location /grafana/ {
proxy_pass http://grafana_server/;
proxy_set_header Host $host;
}
}
But changing it to dashboard and navigating to https://example.com/dashboard/dashboard/new?orgId=1 results in the url been rewritten to https://example.com/dashboard/new?orgId=1
grafana.ini:
[server]
http_addr = 127.0.0.1
domain = example.com
root_url = %(protocol)s://%(domain)s/dashboard/
nginx config:
# Upstream Servers
upstream grafana_server {
server localhost:3000;
}
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
include snippets/ssl-example.com.conf;
include snippets/ssl-params.conf;
root /var/www/example.com/html;
index index.html index.htm;
server_name example.com www.example.com;
location /dashboard/ {
proxy_pass http://grafana_server/;
proxy_set_header Host $host;
}
}
so I have tried a to do a rewrite in the nginx location but can't get it to work as required (really have no clue what to do here)
location ~ (\/dashboard\/) {
proxy_pass http://grafana_server$1;
proxy_set_header Host $host;
}
location ~ /dashboard/ {
rewrite ^ /dashboard/$1;
proxy_pass http://grafana_server;
proxy_set_header Host $host;
}
Any help would be much appreciated.
Regards,
I know this is a bit late - but I stumbled upon the same issue and thought I'd going to share in case somebody else hits this thread:
This isn't an issue with nginx, but with grafana itself.
I could not solve it any other way but renaming the last part of the root_url in something different than /dashboard

Too many redirects - changing naked url -> www.example.com

I've changed my conf file so that when a user types in the domain without www it redirects to the domain with www:
server_name example.com;
return 301 $scheme://www.example.com$request_uri;
I also wish for my https for anything under /user
I get the error of too may redirects, where am I going wrong?
So I have:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/example.com/site;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name example.com;
return 301 $scheme://www.example.com$request_uri;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location /user {
rewrite ^ https://$http_host$request_uri? permanent;
}
}
For port 443:
server {
listen 443;
server_name example.com;
return 301 $scheme://www.example.com$request_uri;
root /var/www/example.com/site;
index index.html index.htm;
ssl on;
ssl_certificate //path here
ssl_certificate_key //path here
location / {
rewrite ^ http://$http_host$request_uri? permanent;
}
location /user {
}
}
With
listen 80 default_server;
you are telling nginx that this server block is the default server for all http requests regardless of the server name.
The directive
return 301 $scheme://www.example.com$request_uri;
sets nginx to redirect all incoming traffic for this server block to www.example.com. That redirected traffic hits the same server block again (default server) and the process repeats itself, hence a redirect loop.
To fix this change your config file and add a second server block:
server {
listen 80;
listen [::]:80 ipv6only=on;
server_name www.example.com;
#rest of your config
[...]
}
server {
server_name example.com;
return 301 $scheme://www.example.com$request_uri;
}
Port 80 can be left out, as it is the default, in case you are wondering.
The same principle applies to traffic for 443 (in the redirect block you however must give the port and ssl specific configuration).

Nginx URL masking to a different domain

There's a few similar questions on SO, but none exactly mine, and I've had no luck trying to adapt their answers so far.
I want to map the URL http://sub.example.com to https://123.12.12.12/path, such that the browser still shows the URL http://sub.example.com.
My Nginx config file looks like,
server {
listen 80;
server_name sub.example.com;
location / {
proxy_pass https://123.12.12.12;
rewrite ^/$ /path last;
}
}
The routing works here, but the URL displayed is http://sub.example.com/path. How do I make it display only http://sub.example.com?
server {
listen 80;
server_name sub.example.com;
location / {
proxy_pass https://123.12.12.12/path;
}
}
Thats how it works. If proxy_pass contains locations part - current location will be replaced to specified. http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
But it's help only for http request and http redirects. If application create html with links https://123.12.12.12 - it's still unchanged. In this case you can try ngx_http_sub_module.
I did like this:
server {
listen 80;
listen [::]:80;
listen 443 http2 ssl;
listen [::]:443 http2 ssl;
server_name domain1;
if ($request_method ~* OPTIONS|GET|HEAD) {
return 301 https://domain2$request_uri;
}
location ~* api {
proxy_pass https://domain2$request_uri;
}
}
Because post-requests will cause a 405 error when redirecting.

Nginx convert subdomain to path component without redirect

The idea is to take incoming requests to http://abc.example.com/... and rewrite them to http://example.com/abc/...
That's easy enough to do with a 301/302 redirect:
# rewrite via 301 Moved Permanently
server {
listen 80;
server_name abc.example.com;
rewrite ^ $scheme://example.com/abc$request_uri permanent;
}
The trick is to do this URL change transparently to the client when abc.example.com and example.com point at the same Nginx instance.
Put differently, can Nginx serve the contents from example.com/abc/... when abc.example.com/... is requested and without another client round trip?
Starting Point Config
Nginx config that accomplishes the task with a 301:
# abc.example.com
server {
listen 80;
server_name abc.example.com;
rewrite ^ $scheme://example.com/abc$request_uri permanent;
}
# example.com
server {
listen 80;
server_name example.com;
location / {
# ...
}
}
# abc.example.com
server {
listen 80;
server_name abc.example.com;
location / {
proxy_pass http://127.0.0.1/abc$request_uri;
proxy_set_header Host example.com;
}
}

Resources