Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virtual hosts missing the "return 301" part to redirect www to non-www and vice versa #440

Closed
nemseck opened this issue Mar 12, 2024 · 3 comments

Comments

@nemseck
Copy link

nemseck commented Mar 12, 2024

CloudPanel version(s) affected

2.4.1

Description

I've installed Cloudpanel on two different VM, both are using Ubuntu 22.04. One has a public IP resolution while the other is on my local machine just for testing purposes.

While the one on local environment is working exactly as expected, the one with public IP has a problem that comes out at every new virtual host creation.

This is the right standard configuration that comes out on the environment working properly

**server {
  listen 80;
  listen [::]:80;
  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  {{ssl_certificate_key}}
  {{ssl_certificate}}
  server_name mylocaltest.mr;
  return 301 https://www.mylocaltest.mr$request_uri;
}**

server {
  listen 80;
  listen [::]:80;
  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  {{ssl_certificate_key}}
  {{ssl_certificate}}
  server_name www.mylocaltest.mr www1.mylocaltest.mr;
  {{root}}
  etc etc..
  

Instead this is the virtual host that comes out on the enviroment that is missing the bold part of the previous example

server {
  listen 80;
  listen [::]:80;
  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  {{ssl_certificate_key}}
  {{ssl_certificate}}
  server_name www.mypublictest.it;
  {{root}}
  etc et ..
  

How to reproduce

I don't know how to reproduce this issue, I've analyzed all the files under /home/clp/ folders and also confronted all the etc/nginx/nginx.conf files of both environments.

I feel like there's something that is not including properly the rules stored in home/clp/htdocs/app/files/resources/nginx/vhost_template/redirect file (checked also this one, which is ok in both environments).

Possible Solution

I know that a solution would be manually adding the missing rules but I'd like to have the standard behaviour of Cloudpanel virtual hosts generation.

Additional Context

Please note that on the "bugged" environment, at the end of installation I had this alert:

dpkg: error processing package cloudpanel (--configure): installed cloudpanel package post-installation script subprocess returned error exit status 1
E: Sub-process /usr/bin/dpkg returned an error code (1)

Anyway after I solved this issue I successfully performed an "apt reinstall cloudpanel" to complete post-installation scripts.

@cloudpanel-io
Copy link
Owner

I don't see any problem. In the example below, the following redirections are working:

http://moby.io -> 301 --> https://www.moby.io
https://moby.io --> 301 --> https://www.moby.io
http://www.moby.io -> 301 --> https://www.moby.io

Can you please explain the issue more detailed?

server { listen 80; listen [::]:80; listen 443 ssl http2; listen [::]:443 ssl http2; {{ssl_certificate_key}} {{ssl_certificate}} server_name moby.io; return 301 https://www.moby.io$request_uri; }

server {
listen 80;
listen [::]:80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
{{ssl_certificate_key}}
{{ssl_certificate}}
server_name www.moby.io www1.moby.io;
{{root}}

@nemseck
Copy link
Author

nemseck commented Apr 12, 2024

Thanks, what I meant is that on my Cloudpanel installation, by default, the first redirection part is missing.
So every time I create a new virtual host, I have to manually add:

server {
 listen 80;
  listen [::]:80;
  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  {{ssl_certificate_key}}
  {{ssl_certificate}}
  server_name mylocaltest.mr;
  return 301 https://www.mylocaltest.mr$request_uri;
}

when in my local environment this part is automatically (and correctly) generated by default by Cloudpanel itself.

@cloudpanel-io
Copy link
Owner

Cannot be reproduced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants