I'm trying to reverse proxy using nginx from subdomain to url served by Laravel (version 5.2). In my top domain (domain.com) it's served on url domain.com/sub
. I want it accesible by domain sub.domain.com
. It should proxy sub.domain.com
to serve same thing with domain.com/sub
. Here's my nginx conf for reverse proxy
server {
listen 80;
server_name sub.domain.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://domain.com/sub;
}
}
Here's my nginx conf for laravel app
server {
listen 80;
listen [::]:80;
# Useful logs for debug.
access_log /var/www/domain/access.log;
error_log /var/www/domain/error.log;
rewrite_log on;
root /var/www/domain/public;
index index.php index.html index.htm;
server_name domain.com local.domain;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
}
But it returned 500 internal server error
. Any suggestion to fix it or how to achieve that? Thanks :)
I've found it's problem and solution from here Nginx reverse proxy causing infinite loop
Looks like I set proxy_header host, thats what created loop. So I commented proxy_header host. Here's my full conf
server {
listen 80;
server_name sub.domain.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://domain.com/sub;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.