Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Re: Nginx proxy for wildcard domain

$
0
0
I'm using Nginx-1.8.1-1.el6.ngx.x86_64 on Centos 6.4 64 bit, here what I tried :

user nginx;
worker_processes 8;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
charset utf-8;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

log_format proxy '$http_x_forwarded_for - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $request_time $upstream_response_time';

access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;

server {
listen 192.168.201.11:82 default;
server_name _;

access_log /var/log/nginx/access.log main;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

server {
listen 192.168.201.11:80 default_server;
server_name *.domain.com;
return 301 https://$server_name$request_uri;
}

server {
listen 192.168.201.11:443 ssl;
ssl_certificate /opt/certificate/cert.crt;
ssl_certificate_key /opt/certificate/cert.key;
server_name *.domain.com;

access_log /var/log/nginx/proxy-access.log proxy;
error_log /var/log/nginx/proxy-error.log;
include proxy_params;
add_header X-Proxy-Cache $upstream_cache_status;

location / {
proxy_pass http://http;
}
}

upstream http {
ip_hash;
server 192.168.201.11:82 weight=1 max_fails=3 fail_timeout=30s;
}

server {
listen 192.168.201.11:82;
server_name domain.com;
access_log /var/log/nginx/domain/domain-access.log proxy;
error_log /var/log/nginx/domain/domain-error.log;
root /opt/www/domain/;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.html index.php;
}

location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /opt/www/domain$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}

server {
listen 192.168.201.11:82;
server_name management.domain.com;
access_log /var/log/nginx/management/management-access.log proxy;
error_log /var/log/nginx/management/management-error.log;
root /opt/www/management/;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.html index.php;
}

location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /opt/www/management$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}

server {
listen 192.168.201.11:82;
server_name *.domain.com;
access_log /var/log/nginx/wildcard-domain/wildcard-domain-access.log proxy;
error_log /var/log/nginx/wildcard-domain/wildcard-domain-error.log;
root /opt/www/wildcard-domain/;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.html index.php;
}

location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /opt/www/wildcard-domain$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}

But it doesn't work.
http://domain.com redirect to https://domain.com
http://management.domain.com or something.domain.com redirect to https://%2A.domain.com/

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>