Nginx两个服务器块监听80和81不工作



在/etc/nginx/sites-available中我有这两个三个文件:

默认

server {
listen 80 default_server;
listen [::]:80 ipv6only=on default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
include /etc/nginx/sites-available/ios_conciseph.conf;
include /etc/nginx/sites-available/conciseph.conf;

conciseph.conf

server{
listen 80;
server_name staging.app.conciseph.com;
passenger_enabled on;
passenger_spawn_method direct;
passenger_min_instances 1;
passenger_app_env staging;
#passenger_ruby /usr/local/rvm/rubies/ruby-2.7.0/bin/ruby;
passenger_ruby /usr/local/rvm/gems/ruby-2.7.0/wrappers/ruby;
root /var/www/conciseph/public;
location ~ ^/assets/ {
gzip_static on;
add_header Cache-Control public;
expires 4w;
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_disable "MSIE [1-6].";
gzip_comp_level 6;
gzip_types application/x-javascript text/css text/html image/x-icon image/png image/jpeg image/gif image/jpg;
}
location / {
root /var/www/conciseph/public;
autoindex off;
#proxy_cache conciseph;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
proxy_cache_revalidate on;
proxy_cache_min_uses 2;
proxy_cache_lock on;
passenger_enabled on;
log_not_found off;
if ($http_user_agent ~ (libwww|Wget|LWP|damnBot|BBBike|java|spider|crawl) ) {
return 403;
}
}
location ~* .(?:ico|css|js|gif|jpe?g|png)$ {
expires 30d;
add_header Pragma public;
add_header Cache-Control "public";
}
}

ios_conciseph.conf

server{
listen 81;
server_name staging.app.conciseph.com:81;
passenger_enabled on;
passenger_spawn_method direct;
passenger_min_instances 1;
passenger_app_env staging;
#passenger_ruby /usr/local/rvm/rubies/ruby-2.7.0/bin/ruby;
passenger_ruby /usr/local/rvm/gems/ruby-2.7.0/wrappers/ruby;
root /var/www/ios_conciseph/conciseph/public;
location ~ ^/assets/ {
gzip_static on;
add_header Cache-Control public;
expires 4w;
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_disable "MSIE [1-6].";
gzip_comp_level 6;
gzip_types application/x-javascript text/css text/html image/x-icon image/png image/jpeg image/gif image/jpg;
}
location / {
root /var/www/ios_conciseph/conciseph/public;
autoindex off;
#        proxy_cache conciseph;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
proxy_cache_revalidate on;
proxy_cache_min_uses 2;
proxy_cache_lock on;
passenger_enabled on;
log_not_found off;
if ($http_user_agent ~ (libwww|Wget|LWP|damnBot|BBBike|java|spider|crawl) ) {
return 403;
}
}
location ~* .(?:ico|css|js|gif|jpe?g|png)$ {
expires 30d;
add_header Pragma public;
add_header Cache-Control "public";
}
}

当我点击staging.app.conciseph.com/users/sign_up时,它给了我预期的响应但是当我点击staging.app.conciseph.com:81/users/sign_up时,它继续加载,并最终提出错误"此站点无法访问">

我甚至不能在/var/log/nginx/access.log

中找到任何正在处理的请求我想使用两个不同的url运行相同的应用程序。

文件夹1在里面:/var/www/conciseph &文件夹二路径:/var/www/ios_conciseph/conciseph

我注意到您在服务器名称字段中包含了端口。尝试删除端口并重新检查,根据nginx确定的服务器名称,您可能没有包含端口(参见http://nginx.org/en/docs/http/server_names.html)。

正如您在Host字段中看到的,通常不包含端口,因此您没有机会将其与包含端口的服务器名称相匹配:

$ curl -v staging.app.conciseph.com
$ curl -v staging.app.conciseph.com:80
$ curl -v staging.app.conciseph.com:81
$ curl -v staging.app.conciseph.com
...
> GET / HTTP/1.1
> Host: staging.app.conciseph.com
> User-Agent: curl/7.81.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 404 Not Found
< Content-Type: text/html; charset=UTF-8
< Content-Length: 1722
< Connection: keep-alive
< Status: 404 Not Found
...

由于在访问日志中看不到任何请求,您可能需要检查您的防火墙并查看nginx错误日志。

最新更新