Answer the question
In order to leave comments, you need to log in
How to complete proxying on nginx with ssl?
Well, let's get started :)
There are 2 servers, the main one and for requesting traffic. I installed the VestaCP control panel on both to quickly set everything up and not bother.
I successfully made http traffic proxying, but I have an ssl certificate on the site and everything flies. I will not show the site and IP addresses, as I am worried about my resource.
site_name - site name
Serv1 - main server
Serv2 - proxy server
mIP1 - main server IP
mIP2 - proxy server IP
Serv2 config:
server {
listen mIP2:443;
server_name site_name www.site_name;
root /home/admin/web/site_name/public_html;
index index.php index.html index.htm;
access_log /var/log/nginx/domains/site_name.log combined;
access_log /var/log/nginx/domains/site_name.bytes bytes;
error_log /var/log/nginx/domains/site_name.com.error.log error;
ssl on;
ssl_certificate /home/admin/conf/web/ssl.site_name.pem;
ssl_certificate_key /home/admin/conf/web/ssl.site_name.key;
location / {
proxy_pass https://mIP1:443;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header realip $remote_addr;
try_files $uri $uri/ /index.php?$uri&$args;
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
expires max;
}
location ~ [^/]\.php(/|$) {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
}
server {
listen mIP1:443;
server_name site_name www.site_name ;
# if ($http_user_agent ~* (WordPress/4)) {
# return 444;
# }
# if ($server_protocol = "HTTP/1.0") {
# return 444;
# }
# if ($http_user_agent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0") {
# return 444;
# }
# if ($http_user_agent ~* (2743.116|2311.135|2704.103)) {
# return 444; }
root /home/admin/web/site_name /public_html;
index index.php index.html index.htm;
access_log /var/log/nginx/domains/site_name .log combined;
access_log /var/log/nginx/domains/site_name .bytes bytes;
error_log /var/log/nginx/domains/site_name .error.log error;
ssl on;
ssl_certificate /home/admin/conf/web/ssl.site_name .pem;
ssl_certificate_key /home/admin/conf/web/ssl.site_name .key;
location / {
set_real_ip_from mIP1;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
try_files $uri $uri/ /index.php?$uri&$args;
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
expires max;
}
location ~ [^/]\.php(/|$) {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass 127.0.0.1:9004;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
}
rewrite ^ https://site_name/$request_uri? permanent;
if ($host != site_name) {
rewrite ^(.*) https://site_name/$request_uri? permanent;
}
Answer the question
In order to leave comments, you need to log in
Press f12 on the browser page, you will see that the styles did not load, because they are registered via http. Look for the place of the hardcode in the engine and change, as mentioned above, http to //.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question