I'm trying to configure some 301 permanent redirects for some pages that have been moved (to a sub-folder of '/local'). My local environment, the test server and the live server all run on nginx, which I am new to. My local environment is set up with Homestead and I am trying to get the redirects to work there first.
I have ssh'd to my homestead vm, and edited the file /etc/nginx/nginx.conf: I have added this server block within the http block:
server {
server_name local.kkds;
location /essex {
rewrite ^/essex(.*)$ /local/essex$1 permanent;
}
}
When I include the server_name and do sudo nginx -s reload, I get the message
nginx: [warn] conflicting server name "local.kallikids" on 0.0.0.0:80, ignored
The urls redirect but all pages display an nginx 404 page, except the homepage which displays 'Welcome to nginx' page.
If I comment out the server_name the rest of the site works as it should but the redirects don't happen. I also tried replacing the server name with ip address in my homestead.yaml file and with 0.0.0.0 but still the redirect are not happening.
Perahps I am placing the configuration in the wrong place? Can someone point me in the right direction?
Related
I am having a hard time getting subdomains to work locally. I have Docker serving the application to port 8080, and I am able to see the Laravel welcome screen. I then have a simple route setup like this:
Route::domain('{name}.localhost:8087')->group(function () {
return 'Hello World';acrylic dns
});
I am using Laravel's basic server, i.e. php artisan serve --host=0.0.0.0 --port=8087
When I try and view the page, nothing happens. It just goes to the welcome screen. I have even tried adding 'test.localhost' to the /etc/hosts file. Couple questions:
1) Can you have the port in the host like I have it there (in the Laravel route)?
2) I have seem somewhat similar posts where the solution was to use acrylic dns (on windows). I am using a Mac. Is this something where I need an actual DNS server?
3) I am planning on using nginx, do I need a 'beefier' web server to accomplish this?
With the basic Laravel server I have tried hard coding test.localhost in the route, with and without the port. I'm sure I am goofing something up, just not sure where. I am on a Mac, and I am running Laravel 5.6. Thanks in advance!
1) No, the web server configuration will listen on the port.
// nginx
server {
listen 8080;
...
}
2) You add the subdomains in your /etc/hosts file and create separate nginx configurations:
// /etc/hosts
subdomain1.foo.localhost 127.0.0.1
subdomain2.foo.localhost 127.0.0.1
subdomain3.foo.localhost 127.0.0.1
// nginx subdomain1.foo.localhost.conf
server {
listen 8080;
server_name subdomain1.foo.localhost;
...
}
// nginx subdomain2.foo.localhost.conf
server {
# set different port if needed
# listen 8082
listen 8080;
server_name subdomain2.foo.localhost;
...
}
// nginx subdomain3.foo.localhost.conf
server {
# set different port if needed
# listen 8083
listen 8080;
server_name subdomain3.foo.localhost;
...
}
3) Nginx is a production ready web server, you may need load balancers and multiple instances of the web servers to scale out, but nginx will be more than sufficient.
If you're using Artisan serve, go to
/etc/hosts (or similar)
127.0.0.1 subdomain.localhost
And open in the browser
subdomain.localhost:8087
I want to redirect cnn.com on my local Mac OSX to a 404 page. Here is what I have currently, but cnn.com still works (and redirects to edition.cnn.com):
/etc/hosts
127.0.0.1 cnn.com
/usr/local/etc/nginx/nginx.conf
# some config
http {
# some config
server {
listen 80;
server_name cnn.com;
location / {
return 404;
}
}
# more config
}
# more config
Or, is there a better way to accomplish this using another service?
The requested URL /myapp/welcome/login was not found on this server.
Apache/2.4.9 (Win64) PHP/5.5.12 Server at localhost Port 80
codeigniter not found my site on local host
First check your site directory, if it has a .htaccess you need to activate mod_rewrite on your wamp server.
For this follow this picture and open httpd.conf file, search just "rewrite" and remove "#" from start of this. save your file and restart your server by clicking "Restart All Services".
How Can i setup virtual host for laravel-4 ?
Previously I wrote some code and routes looked like -
Route::get('/', 'PageController#home');
Route::get('/home', 'PageController#about');
when I gave the url - "http://localhost/laravel-master/public/" I can see the home page but when tired "http://localhost/laravel-master/public/about" i got error saying url not found.
I tired configuring virtual host but ended up with the error - You don't have permission to access"url" on this server.
What is the correct way to do this ??
the path to my laravel folder is "C:\wamp\www\laravel-master"
and instead of using "http://localhost/laravel-master/public/" i wish to use url like "myapp" or so, So that when i use myapp I can see the home page and when I use "myapp/about" I can see the about page.
You need to add your virtualhost and host file.Make your apache listen to your Url.
Something like in your virtualhost file
<VirtualHost laravel>
DocumentRoot "C:/wamp/www/laravel-master/public"
ServerName laravel
</VirtualHost>
And in your host file:
127.0.0.2 laravel
make apache restart and your clean URL will work.
i'm using wamp 5, windows XP. i have edited my host file in my local disk like the code below and it works
127.0.0.0 example.com
but i'd like to redirect to a particular folder, if i change it to the code below, it dont work
127.0.0.0/main/site example.com
how to redirect example.com to 127.0.0.0/main/site locally in my PC?
btw, i dont want to install any new software to solve this prob
You need to create a Virtual Hosts
Leave the HOST file as
127.0.0.1 example.com
When you define a Virtual Host you also tell it which folder is its DocumentRoot so that will send it to the right place when you use the address example.com in the browser.
Check out wampserver.com