server {
listen 80;
server_name example.com;
location / {
rewrite ^/(.*)$ https://$host$1 permanent;
}
}
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/ssl/example.crt;
ssl_certificate_key /etc/ssl/example.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
location / {
proxy_pass https://www.google.com;
proxy_set_header Host www.google.com;
proxy_set_header Referer https://www.google.com;
proxy_set_header User-Agent $http_user_agent;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Accept-Encoding "";
proxy_set_header Accept-Language $http_accept_language;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
sub_filter google.com example.com;
sub_filter_once off;
}
}
I am trying to use this, but 0.0.0.0:80 is in use by apache, but the question is how can I reverse proxy a request from bi.example.com to google.com while still having webservice.example.com redirect the request to example.com which hosts an API webservice. I don't think it can be done, but I am probably wrong.
I got this error when I tried to start nginx:
Dec 28 10:52:22 example.com nginx[27291]: nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address al...use)
Dec 28 10:52:23 example.com nginx[27291]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address alr...use)
Dec 28 10:52:23 example.com nginx[27291]: nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address al...use)
Dec 28 10:52:23 example.com nginx[27291]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address alr...use)
Dec 28 10:52:23 example.com nginx[27291]: nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address al...use)
Dec 28 10:52:24 example.com nginx[27291]: nginx: [emerg] still could not bind()
I checked the ports and it was being used by httpd, which corresponds to Apache.
To explain further, I have two CNAME redirect to example.com, and I want to redirect to a different page than Google, but this is just an example, so because both CNAME redirects to the same url, I don't think this is possible and a redirect from an url to another url to provide a SSL certificate to another link than Google.com is not possible if port 80 is used by Apache. Aside using a brand new server for this, are there any other possibilities? Right now, there's a CNAME redirect from bi.example.com to another url than Google, and I tried to set up a redirect with nginx by pointing the CNAME from bi.example.com to example.com instead of the other url.