I need help with my nginx settings for multiple sites


(Paul Schlacter) #1

Hi,

i have 3 conf that i’ve tried to put inside sites-enabled and conf.d. i wonder why it’s not working.

root@mahanavo:/etc/nginx/conf.d# cat discourse.conf
server {
# Listen on HTTP ( port 80 )
listen 80;

# Set Server Name to discourse.dhammanussati.com
# So this server block will only serve if the user
# access it via that host
server_name discourse.dhammanussati.com;
# Set Logs Locations
access_log /var/log/nginx/discourse.acccess.log;
error_log /var/log/nginx/discourse.error.log;
# Serve Root Location with files according to the URL
# If it doesn't exists, return 404
location / {
    try_files $uri $uri/ =404;
            proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock:;
            proxy_set_header Host $http_host;
            proxy_http_version 1.1;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

}

root@mahanavo:/etc/nginx/conf.d# cat dhammanussati.conf
server {
# Listen on HTTP ( port 80 ) as default server If there’s no other server block which have their own Server
# Name ( like discourse ), It’ll go to this server block
listen 80 default_server;

listen 80; listen [::]:80;

# Set the Server Name We actually don't need this, but meh.
server_name dhammanussati.com www.dhammanussati.com;
# Set Root Directory
root /var/www/html/;
# Define Index Files
index index.html index.htm;
# Set Logs Locations
access_log /var/log/nginx/main.acccess.log;
error_log /var/log/nginx/main.error.log;
# Serve Root Location with files according to the URL If it doesn't exists, return 404
location / {
    #try_files $uri $uri/ =404;
    try_files $uri $uri/ =404;
            proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock:;
            proxy_set_header Host $http_host;
            proxy_http_version 1.1;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

}

root@mahanavo:/etc/nginx/conf.d# cat mail.conf
server {
listen 80;
server_name mail.dhammanussati.com;
root /var/www/webmail;

   if ($http_host != "mail.dhammanussati.com") {
             rewrite ^ http://mail.dhammanussati.com$request_uri permanent;
   }
   index index.php index.html;
   location ~ ^/favicon.ico$ {
            root /var/www/webmail/skins/default/images;
            log_not_found off;
            access_log off;
            expires max;
   }
   location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
   }
   location ~ ^/(README|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ {
            deny all;
   }
   location ~ ^/(bin|SQL)/ {
            deny all;
   }
   # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
   location ~ /\. {
            deny all;
            access_log off;
            log_not_found off;
   }
   location ~ \.php$ {
            try_files $uri =404;
            include /etc/nginx/fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_index index.php;
   }

}

Could somebody help me? i’m hopeless


Running other websites on the same machine as Discourse
(Felix Freiberger) #2

First of all, have you seen this tutorial?

I’m assuming that discourse.conf should route discourse.dhammanussati.com to Discourse running on http://unix:/var/discourse/shared/standalone/nginx.http.sock:.

In that case, the configuration looks fishy, especially the try_files. Try sticking exactly to the template by @riking , only changing server_name:

server {
	listen 80; listen [::]:80;
	server_name forum.example.com;  # <-- change this

	location / {
		proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock:;
		proxy_set_header Host $http_host;
		proxy_http_version 1.1;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	}
}

I’m not sure what you want to do with the other configuration files :frowning:


#3

Didn’t we get your figured out here?

You had a working instance there. So the question is what further are you attempting to accomplish?

Why are you redirecting the www and mail subdomain to the discourse proxy? Are these going to be running discourse? Your other services don’t require the proxy. Revert back to your working model.


(Paul Schlacter) #4

it works fine before but when i open my domain, it opened up my discourse. so i tried to tweak it and it kinda messed up.


#5

That shouldn’t happen.

You just have to set up the server name for each conf file and their correct directory.

Leave the discourse.conf as is, and set the servername and web directory for your other sites and it won’t redirect.

Remove the proxy pass for your other sites.


(Paul Schlacter) #6

oh it works now =.= i didn’t change the location into the exact location. oh boy


(Paul Schlacter) #7

the problem now is my mail.conf is not working. i don’t know why