How can I rewrite a subdomain to an application in NGINX?
My configuration is
server {
listen 80;
server_name domain.com www.domain.com;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:9001;
uwsgi_param UWSGI_PYHOME PATH;
uwsgi_param UWSGI_SCRIPT wsgi;
uwsgi_param UWSGI_CHDIR PATH;
}
location /app1 {
include uwsgi_params;
uwsgi_pass 127.0.0.1:9001;
uwsgi_param UWSGI_PYHOME PATH2;
uwsgi_param UWSGI_SCRIPT wsgi2;
uwsgi_param UWSGI_CHDIR PATH2;
uwsgi_modifier1 30;
}
}
I want to when access app1.domain.com I got rewrited to domain.com/app1. How can I do this?
Thanks in advance.
You can either just add the sub-domain to the server name in which case it will just work as the domain but the user will not be redirected and the address bar will show the sub-domain:
server {
listen 80;
server_name domain.com www.domain.com app1.domain.com;
location / {
include uwsgi_params;
...
}
}
Alternatively, you can create a specific server for the sub-domain which redirects to the domain:
server {
listen 80;
server_name app1.domain.com;
rewrite ^ http://domain.com$request_uri? permanent;
}
server {
listen 80;
server_name domain.com www.domain.com;
location / {
include uwsgi_params;
...
}
}
I don't think you need to - you can add another server section like:
server {
server_name app1.domain.com;
location / {
<uwsgi as before>
}
}
rather than a location /app1 followed by a redirect. Hope that helps.
Related
I have a web page currently hosted at https://somesite.zz/foo/. When loaded, that returns https://somesite.zz/foo/index.html, which loads various CSS and JavaScript using relative paths:
<link rel="stylesheet" href="default.css"/>
<script type="text/javascript" src="scripts.js"></script>
Since the paths are relative, the browser loads https://somesite.zz/foo/default.css and https://somesite.zz/foo/scripts.js and everyone is happy. The problem is when someone omits the trailing slash and loads https://somesite.zz/foo. The server still returns the contents of https://somesite.zz/foo/index.html, but now the browser doesn't realize that it is in a subdirectory so the relative paths are wrong: it tries to load https://somesite.zz/default.css and https://somesite.zz/scripts.js. Those 404, of course, so nothing works.
How can I redirect /foo to /foo/ (or otherwise make them equivalent)? I can't use JS in index.html because of my CSP: any JS needs to be in an external file, which I can't load because the paths are wrong. So this probably can't be solved using JS. This site is hosted on AWS Cloudfront + S3; is there a way to configure such a redirect there?
With a little more research, I discovered that request-triggered Cloudfront Functions can return responses, so I created the following function with the "viewer request" trigger:
function handler(event) {
var request = event.request;
var uri = request.uri;
if (uri.endsWith('/')) {
request.uri += "index.html";
} else {
var leafIdx = uri.lastIndexOf('/');
if ((-1 != leafIdx) && (!uri.substring(leafIdx+1).includes('.'))) {
return {
statusCode: 301,
statusDescription: "Redirect",
headers: {
"location": { "value": request.uri + "/index.html" }
}
}
}
}
return request;
}
The first branch of that function does the typical silent "redirect" to index.html. In the second, I check if the last path component appears to be a file or directory based on the presence or absence of a '.' in the name; anything without a '.' is interpreted as a directory and a 301 redirect is issued. Since this this is a real HTTP redirect, the browser knows to change its path, avoiding my relative-path problem.
I am attempting to connect all browser traffic through my SOCKS5 server, but have had no luck so far. I have read the docs, e.c.t
I am trying to get something like this working:
https://github.com/txthinking/socks5-configurator/blob/master/options.js
Here is my current code:
var config = {
mode: "fixed_servers",
rules: {
proxyForHttp: {
scheme: "socks5",
host: ip,
port: port
},
bypassList: ["mygeoip.co"]
}
};
chrome.proxy.settings.set(
{value: config, scope: 'regular'},
function() {}
);
For some reason it does not connect, it does not do anything. I have managed to get an http server running in the past with a pre-loaded PAC script, but this does not work.
Big up vote to whoever can help me out.
I am working on a project which needs a subdomain and a main domain.
So I wrote some changes on the boot function of RouteServiceProvider, as mentioned below. It's working fine on localhost, but on the server, both main and subdomain return 404.
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
// Main domain routes.
Route::domain(config('constants.app_url'))
->middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
// SubDomain Routes.
Route::domain('users.'.config('constants.app_url'))
->middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web_user.php'));
});
}
We've got a page that we put up on our website when we take it down for maintenance or updates. The basic pseudocode logic looks something like this:
if IP != 72.56.43.212 and location !~ /down then
display down/
It's important that the url remain intact. For example,
Address Bar: http://www.example.com/abcd.html
Page Shown: http://www.example.com/down
I'm still pretty new to NGINX configuration. Any help is appreciated.
Never really tried this my self before, but you can use the nginx access rules to do this
error_page 403 http://example.com/down.html;
location / {
allow 72.56.43.212;
deny all;
}
if ($remote_addr != "1.1.1.1") {
rewrite . /down last;
}
location /down {
#empty block
}
location / {
if ($remote_addr != 72.56.43.212) {
rewrite ^ /down/index.php last;
}
}
In my apphost.cs file I have defined unauthorized requests to open login.cshtml.
SetConfig(new EndpointHostConfig
{
CustomHttpHandlers =
{
{HttpStatusCode.NotFound, new RazorHandler("NotFound")},
{HttpStatusCode.Unauthorized, new RazorHandler("login")},
}
});
I'm running the project self hosted. I have deployed the project to a server (Debian+Apache: ProxyPass to http://127.0.0.1:2008).
My problem is that the redirect link(querystring) links back to http://127.0.0.1:2008/People.
http://servername/login?redirect=http://127.0.0.1:2008/People
How can I override the redirect url to point to http://servername/People?
Try specifying the server url you wish to use in your config, e.g:
SetConfig(new HostConfig {
WebHostUrl = "http://servername/"
});