Answer the question
In order to leave comments, you need to log in
How does nginx + apache2 + let's encrypt work?
Can't set up https when using nginx
As far as I understand, nginx listens on ports :80 and :443, while apache only listens on :8080.
When a request is made to the server, all configs from /etc/nginx/sites-enabled/ are loaded first.
If the server_name matches, then the appropriate test config is executed, if there are none, then the default config is executed, in which server_name localhost is specified.
Inside test, if port is 80, the request is redirected to the 433rd.
In 443, the /etc/letsencrypt/live/test.example.com/fullchain.pem keys are registered
From 443, if a script is requested, the request is redirected to 127.0.0.1:8080 and apache intercepts it.
there, a suitable config is loaded from ServerName test.example.com and the specified script is executed.
But in my case, an invalid certificate error occurs. The page opens correctly, so the general route is correct. What causes such problems?
Config /etc/nginx/sites/enabled/test:
server {
listen 80;
server_name test.example.com;
rewrite ^ https://$host$request_uri? permanent;
}
server {
listen 443 ssl;
server_name test.example.com;
ssl_certificate /etc/letsencrypt/live/test.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/test.example.com/privkey.pem;
# Turn on OCSP stapling as recommended at
# https://community.letsencrypt.org/t/integration-guide/13123
# requires nginx version >= 1.3.7
ssl_stapling on;
ssl_stapling_verify on;
location /.well-known {
alias /var/www/test/.well-known;
}
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
}
location ~ /\.ht {
deny all;
}
}
<VirtualHost 127.0.0.1:8080>
ServerName test.example.com
ServerAdmin [email protected]
DocumentRoot /var/www/test
ErrorLog /var/log/apache2/test/error.log
CustomLog /var/log/apache2/test/access.log combined
<Directory /var/www/test>
AllowOverride All
Options -Indexes
</Directory>
#RewriteEngine on
#RewriteCond %{SERVER_NAME} =test.example.com
#RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question