这应该很简单,但我整天都在努力设置它。这是我的配置文件:
# Expires map
map $sent_http_content_type $expires {
default off;
text/html epoch;
text/css max;
application/javascript max;
~image/ max;
}
server {
listen 80;
server_name www.firstdomain.com firstdomain.com;
root /path/to/project/;
error_log /var/log/nginx/error.log;
}
server {
listen 443 ssl http2; # managed by Certbot
server_name www.firstdomain.com;
error_log /var/log/nginx/error.log;
proxy_read_timeout 90;
expires $expires;
location / {
include proxy_params;
proxy_read_timeout 90;
proxy_pass http://xx.xxx.xxx.xxx:8001;
}
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
alias /path/to/static/;
}
location /media/ {
alias /path/to/media/;
}
location /robots.txt {
alias /path/to/robots.txt;
}
ssl_certificate /etc/letsencrypt/live/firstdomain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/firstdomain.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
if ($host = 'firstdomain.com') {
return 301 https://www.firstdomain.com$request_uri;
}
if ($scheme != "https") {
return 301 https://www.firstdomain.com$request_uri;
} # managed by Certbot
}
这是我的第二个域名,存储在 sites-available 中的单独文件中:
server {
listen 80;
server_name www.second-domain.com second-domain.com;
error_log my-domain-path/nginx.log;
location /
{
proxy_pass http://www.second-domain.com:8002;
}
}
这两个应用程序均由主管管理,并且都成功启动。但是,当我导航到 www.second-domain.com 时,我得到的是 firstdomain.com 的内容。
我确信第二个域名的内容可以工作并运行,因为如果我导航到 IP:PORT 位置,我就可以看到它,但它不能与域名一起使用。
为什么?
编辑:根据请求 nginx -t 的结果
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful