Score:-1

Trouble Formatting Nginx Server Block

tw flag

So I'm trying to set it up where my subdomain: "forum.project-freedom.net" visits the directory of /var/www/forum/ on my server. I'd like the main URL, "project-freedom.net" to be sat on the /var/www/html/ directory of my server. I'm utilizing nginx and here's my current conf file:

server {
    listen 80;
    listen [::]:80;
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name project-freedom.net www.project-freedom.net;

    ssl_certificate /etc/ssl/certs/1546559737repl_1.crt;
    ssl_certificate_key /etc/ssl/private/project-freedom.key;

    root /var/www/html;
    index index.html index.htm index.nginx-debian.html;

    location / {
        try_files $uri $uri/ =404;
    }

    location /forum {
        alias /var/www/forum;
        index index.php index.html index.htm;

        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # Change to match your PHP version
        }
    }

    # Redirect non-www to www
    if ($host = 'project-freedom.net') {
        return 301 https://www.project-freedom.net$request_uri;
    }

    # Redirect HTTP to HTTPS
    if ($scheme != "https") {
        return 301 https://$server_name$request_uri;
    }
}

server {
    listen 80;
    listen [::]:80;
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name forum.project-freedom.net;

    ssl_certificate /etc/ssl/certs/1546559737repl_1.crt;
    ssl_certificate_key /etc/ssl/private/project-freedom.key;

    root /var/www/forum;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # Change to match your PHP version
    }

    # Redirect HTTP to HTTPS
    if ($scheme != "https") {
        return 301 https://$server_name$request_uri;
    }
}
drookie avatar
za flag
Good for ya ! And the question is ... ?
Score:0
tw flag

My question was more so, how am I supposed to structure my .conf file for nginx? When posting this question, it was my first time using Nginx as opposed to Apache.

For anyone in the future who encounters this dilemma, simply set your server_name to subdomain.domain.com (put your domain in place obviously)

Then set your root to the directory you wish the subdomain to be active at.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.