【问题标题】:Can't manage to get nginx working - 301 Moved Permanently #newbie无法让 nginx 工作 - 301 永久移动 #newbie
【发布时间】:2021-12-11 21:27:25
【问题描述】:

这是在 Ubuntu 20.04 上运行的全新服务器,我从未设法显示网页。我是一个真正的新手,所以这个问题可能很愚蠢。我确实查看了其他现有主题,但无法解决我的问题。让我知道是否需要其他东西。

$sudo 服务 nginx 状态

● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2021-12-11 22:02:51 CET; 11min ago
       Docs: man:nginx(8)
    Process: 3534 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 3535 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 3551 (nginx)
      Tasks: 28 (limit: 19660)
     Memory: 411.6M
     CGroup: /system.slice/nginx.service
             ├─3536 Passenger watchdog
             ├─3539 Passenger core
             ├─3551 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ├─3559 nginx: worker process
             ├─3560 nginx: worker process
             ├─3561 nginx: worker process
             └─3683 Passenger RubyApp: /home/decidim/decidim-app (production)

$curl -i http://127.0.0.1/nginx_status

HTTP/1.1 301 Moved Permanently
Content-Type: text/html
Content-Length: 0
Connection: keep-alive
Status: 301 Moved Permanently
Location: https://127.0.0.1/nginx_status
Date: Sat, 11 Dec 2021 21:14:20 GMT
X-Powered-By: Phusion Passenger(R) 6.0.12
Server: nginx/1.18.0 + Phusion Passenger(R) 6.0.12

$sudo tail -f /var/log/nginx/access.log /var/log/nginx/error.log

==> /var/log/nginx/access.log <==
127.0.0.1 - - [11/Dec/2021:21:33:06 +0100] "GET /nginx_status HTTP/1.1" 404 162 "-" "curl/7.68.0"
127.0.0.1 - - [11/Dec/2021:21:41:38 +0100] "GET /nginx_status HTTP/1.1" 404 162 "-" "curl/7.68.0"
127.0.0.1 - - [11/Dec/2021:21:44:28 +0100] "GET /nginx_status HTTP/1.1" 404 162 "-" "curl/7.68.0"
127.0.0.1 - - [11/Dec/2021:21:47:46 +0100] "GET /nginx_status HTTP/1.1" 301 0 "-" "curl/7.68.0"
127.0.0.1 - - [11/Dec/2021:21:47:46 +0100] "GET /nginx_status HTTP/1.1" 301 0 "-" "curl/7.68.0"
127.0.0.1 - - [11/Dec/2021:21:48:09 +0100] "GET /nginx_status HTTP/1.1" 301 0 "-" "curl/7.68.0"
127.0.0.1 - - [11/Dec/2021:21:49:12 +0100] "GET /nginx_status HTTP/1.1" 301 0 "-" "curl/7.68.0"
127.0.0.1 - - [11/Dec/2021:21:54:17 +0100] "GET /nginx_status HTTP/1.1" 301 0 "-" "curl/7.68.0"
127.0.0.1 - - [11/Dec/2021:22:05:13 +0100] "GET / HTTP/1.0" 301 0 "-" "Lynx/2.9.0dev.5 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/3.6.13"
127.0.0.1 - - [11/Dec/2021:22:14:20 +0100] "GET /nginx_status HTTP/1.1" 301 0 "-" "curl/7.68.0"

==> /var/log/nginx/error.log <==
[ N 2021-12-11 22:02:50.9510 3497/Tf Ser/Server.h:901 ]: [ApiServer] Freed 0 spare client objects
[ N 2021-12-11 22:02:50.9510 3497/Tf Ser/Server.h:558 ]: [ApiServer] Shutdown finished
[ N 2021-12-11 22:02:50.9510 3497/T7 Ser/Server.h:901 ]: [ServerThr.1] Freed 0 spare client objects
[ N 2021-12-11 22:02:50.9510 3497/T7 Ser/Server.h:558 ]: [ServerThr.1] Shutdown finished
[ N 2021-12-11 22:02:51.0300 3536/T1 age/Wat/WatchdogMain.cpp:1373 ]: Starting Passenger watchdog...
[ N 2021-12-11 22:02:51.0563 3539/T1 age/Cor/CoreMain.cpp:1340 ]: Starting Passenger core...
[ N 2021-12-11 22:02:51.0564 3539/T1 age/Cor/CoreMain.cpp:256 ]: Passenger core running in multi-application mode.
[ N 2021-12-11 22:02:51.0665 3539/T1 age/Cor/CoreMain.cpp:1015 ]: Passenger core online, PID 3539
[ N 2021-12-11 22:02:53.2192 3539/T5 age/Cor/SecurityUpdateChecker.h:519 ]: Security update check: no update found (next check in 24 hours)
App 3569 output: DeprecatedDSL will be removed from GraphQL-Ruby 2.0, use `.to_non_null_type` instead of `!` and remove `.activate` from /home/decidim/.rben
v/versions/2.7.1/lib/ruby/gems/2.7.0/gems/decidim-core-0.25.2/lib/decidim/core/engine.rb:89:in `block in <class:Engine>'

nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
worker_connections 768;
# multi_accept on;
}

http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}


#mail {
## See sample authentication script at:
## http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
## auth_http localhost/auth.php;
## pop3_capabilities "TOP" "USER";
## imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#server {
#listen     localhost:110;
#protocol   pop3;
#proxy      on;
#}
# 
#server {
#listen     localhost:143;
#protocol   imap;
#proxy      on;
#}
#}

$ls /etc/nginx/sites-enabled/

decidim.conf

$more /etc/nginx/sites-enabled/decidim.conf

server {
    listen 80;
    listen [::]:80 ipv6only=on;

    server_name the_real_ip_adress_I_want_to_hide;
    client_max_body_size 32M;

    passenger_enabled on;
    passenger_ruby /home/decidim/.rbenv/shims/ruby;

    rails_env    production;
    root         /home/decidim/decidim-app/public;
}

【问题讨论】:

    标签: nginx nginx-config


    【解决方案1】:

    正如您在 curl 报告中看到的,重定向到 https 协议是由 Phusion Passenger 发起的。 然后 nginx 无法处理请求,因为没有服务器监听 443 端口。

    【讨论】:

    • 感谢您的回复 Aleksey。我该如何改变呢?
    • 您应该在 /etc/nginx/sites-enabled/decidim.conf 中的服务器块中添加监听 443 指令并配置 https。见手册nginx.org/en/docs/http/configuring_https_servers.html
    • 感谢您的反馈。我设法解决了这个问题。
    猜你喜欢
    • 2017-09-04
    • 2019-11-04
    • 2012-07-10
    • 2013-09-26
    • 2019-10-14
    • 2018-06-18
    • 2018-06-23
    • 2021-08-13
    • 1970-01-01
    相关资源
    最近更新 更多