I'm new to Nginx.
My main goal was to host two Websites for one Domain. I wanted a subdomain hosted separately from the main domain, such as:
- example.com is served from
/home/user/Documents/vue_website/dist
- subdomain.example.com is served from
/var/www/html
Because I run this all on one server I believe this can't be done because they have the same IP address.
I am now trying to get this sorted out by using subdirectories. If i visit example.com/wp it should show the the second site.
Current Nginx site Config looks like this:
server {
listen 80 default_server;
listen [::]:80 default_server;
return 301 https://my-domain.com$request_uri;
}
server {
access_log /var/log/nginx/scripts.log scripts;
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /etc/ssl/my-domain.com.pem;
ssl_certificate_key /etc/ssl/_.my-domain.com_private_key.key;
server_name my-domain.com www.my-domain.com;
location / {
root /home/pi/Documents/vue_website/dist;
index index.html;
}
location /wp {
root /var/www/html/;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 172.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
}
But that doesn't work. I would appreciate any help.
EDIT: So i got the Subdomain working now. But the problem is now that i can only reach it by ssl / typing https in front which i don't want.
So now i am trying to redirect the http request to the given site based on the domain searched
so for example if i go to http://my-domain.com redirect me to https and so on.
Code i got is as follows:
'my-domain.com' '1';
'wp.my-domain.com' '2';
}
server {
listen 80;
if ($new = '1') {
return 301 https://my-domain.com$request_uri;
}
if ($new = '2') {
return 301 https://wp.my-domain.com$request_uri;
}
}
Do i got something wrong in the Code because in my mind it should work like that if i understood it right.