MostHated
asked on
How can I merge these two nginx rules to work properly?
I was running Apache before using an htaccess rule but switched to nginx running a docker instance of the Discourse forum software. I am running nginx outside of the docker instance and then using proxypass so that it is located in domain.com/forum. Before I had it setup as seen below in order to take whatever subdomain is input minus www. and append it to the end of the url. If no subdomain is provided, it would just end up working as normal.
I used a converter from htaccess to nginx which gave me this:
My current location setup looks like this:
So my question is, how can I merge my converted code in the if statement with my current code that contains the proxy_pass stuff? I tried to just put it in there but that just ended up with a loop.
Any insight would be appreciated,
Thanks!
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteCond %{HTTP_HOST} .example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/forum/t/%1$1 [L,NC,QSA]
I used a converter from htaccess to nginx which gave me this:
location / {
if ($http_host !~ "^www\."){
rewrite ^(.*)$ http://example.com/forum/t/%1$1 redirect;
}
}
My current location setup looks like this:
location /forum {
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;
proxy_set_header X-Forwarded-Proto https;
}
fastcgi_read_timeout 60;
}
So my question is, how can I merge my converted code in the if statement with my current code that contains the proxy_pass stuff? I tried to just put it in there but that just ended up with a loop.
Any insight would be appreciated,
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.