raspbian上的nginx服务器导致错误

发布于 2025-01-20 17:58:54 字数 3605 浏览 4 评论 0原文

因此,我成功地在我的服务器上设置了 Nginx、phpmyadmin/php 和 mysql,该服务器由我的树莓派 4 托管。我试图将 Node.js 作为我的后端,并根据在线的各种教程完成所有操作。当我创建反向代理时,我无法访问 phpmyadmin, 然后我开始尝试配置并开始出现错误。

server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;

server_name codenoury.se www.codenoury.se;

location / {
    proxy_pass http://localhost:5000/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
}

# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
    include fastcgi_params;
    # include snippets/fastcgi-php.conf;
    # fastcgi_index index.php
    # fastcgi_param DOCUMENT_ROOT $realpath_root;
    # With php-fpm (or other unix sockets):
    fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
    deny all;
}

我得到的状态代码

是:

root@raspberrypi:/etc/nginx/sites-available# root@raspberrypi:/etc/nginx/sites-available# systemctl status 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: failed (Result: exit-code) since Tue 2022-04-12 20:03:42 CEST; 27min ago
       Docs: man:nginx(8)
    Process: 19140 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
        CPU: 59ms

Apr 12 20:03:42 raspberrypi systemd[1]: Starting A high performance web server and a reverse proxy server...
Apr 12 20:03:42 raspberrypi nginx[19140]: nginx: [emerg] unexpected "}" in /etc/nginx/sites-enabled/codenoury.se:73
Apr 12 20:03:42 raspberrypi nginx[19140]: nginx: configuration file /etc/nginx/nginx.conf test failed
Apr 12 20:03:42 raspberrypi systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Apr 12 20:03:42 raspberrypi systemd[1]: nginx.service: Failed with result 'exit-code'.
Apr 12 20:03:42 raspberrypi systemd[1]: Failed to start A high performance web server and a reverse proxy server.

我已经创建了一个主机为 localhost 的用户和一个主机为网站 ip 地址的用户。 phpmyadmin 位于 /var/www/html/ 上的正确目录(根据来源)

。node.js 应用程序在端口 5000 上运行,正如您在配置文件中看到的那样。 我正在使用简单防火墙(ufw)作为防火墙,如果我检查状态,一切似乎都工作正常:

To                         Action      From
--                         ------      ----
Nginx HTTP                 ALLOW       Anywhere
22/tcp                     ALLOW       Anywhere
80/tcp                     ALLOW       Anywhere
443                        ALLOW       Anywhere
Nginx HTTP (v6)            ALLOW       Anywhere (v6)
22/tcp (v6)                ALLOW       Anywhere (v6)
80/tcp (v6)                ALLOW       Anywhere (v6)
443 (v6)                   ALLOW       Anywhere (v6)

所以问题是:

  1. 如何使 phpmyadmin 工作,并在使用 node.js 作为服务器和使用反向代理时进行访问在端口 80 上,同时让 Node.js 也能工作。
  2. 如何让 nginx 再次工作?

提前致谢。如果您需要任何进一步的信息,请告诉我!

So I managed to setup Nginx and phpmyadmin/php and mysql successfully on my server, which is hosted by my raspberry pi 4. I sought to have Node.js as my backend, and did everything according to the various tutorials there is online. The moment I created the reverse-proxy, I wasnt able to access phpmyadmin,
and then I started playing around with the configuration and the error started to appear.

server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;

server_name codenoury.se www.codenoury.se;

location / {
    proxy_pass http://localhost:5000/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
}

# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
    include fastcgi_params;
    # include snippets/fastcgi-php.conf;
    # fastcgi_index index.php
    # fastcgi_param DOCUMENT_ROOT $realpath_root;
    # With php-fpm (or other unix sockets):
    fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
    deny all;
}

}

The status code I get is:

root@raspberrypi:/etc/nginx/sites-available# root@raspberrypi:/etc/nginx/sites-available# systemctl status 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: failed (Result: exit-code) since Tue 2022-04-12 20:03:42 CEST; 27min ago
       Docs: man:nginx(8)
    Process: 19140 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
        CPU: 59ms

Apr 12 20:03:42 raspberrypi systemd[1]: Starting A high performance web server and a reverse proxy server...
Apr 12 20:03:42 raspberrypi nginx[19140]: nginx: [emerg] unexpected "}" in /etc/nginx/sites-enabled/codenoury.se:73
Apr 12 20:03:42 raspberrypi nginx[19140]: nginx: configuration file /etc/nginx/nginx.conf test failed
Apr 12 20:03:42 raspberrypi systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Apr 12 20:03:42 raspberrypi systemd[1]: nginx.service: Failed with result 'exit-code'.
Apr 12 20:03:42 raspberrypi systemd[1]: Failed to start A high performance web server and a reverse proxy server.

I have created both a user with host = localhost and one with host being the ip-adress to the website. phpmyadmin is located in the right directory (according to sources) on /var/www/html/

The node.js application runs on port 5000 as you can probably see in the configuration file.
I'm using Uncomplicated Firewall (ufw) as firewall, and if I check the status, everything seems to work fine:

To                         Action      From
--                         ------      ----
Nginx HTTP                 ALLOW       Anywhere
22/tcp                     ALLOW       Anywhere
80/tcp                     ALLOW       Anywhere
443                        ALLOW       Anywhere
Nginx HTTP (v6)            ALLOW       Anywhere (v6)
22/tcp (v6)                ALLOW       Anywhere (v6)
80/tcp (v6)                ALLOW       Anywhere (v6)
443 (v6)                   ALLOW       Anywhere (v6)

So the question is:

  1. How can I make phpmyadmin work, and accessible while using node.js as server and using reverse proxy on port 80, while having node.js work as well.
  2. How do I get nginx to work again?

Thanks in advance. Let me know if you require any further information!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文