[英]Nginx two server blocks listen on 80 and 81 not working
在 /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;
簡潔的ph.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 運行同一個應用程序。
文件夾一在里面:/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 錯誤日志。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.