我正在将我的一个项目拉到Vultr框中,以在线查看其开发模式。该项目在localhost:3000
上运行,然后在需要时执行axios GET请求,以从访问localhost:8000
的服务器端获取数据。因此,当我进入盒子的IP地址时,我看到了该项目,但是当我进入其中执行请求的页面时,会出现以下错误:
GET http://localhost:8000/table?tableName=Programs&tableOrder=order+by+id+desc net::ERR_CONNECTION_REFUSED
我相信会发生此错误,因为我没有监听该位置的端口。由于我想避免通过在浏览器URL栏中编写xxx.xxx.xxx.xxx:3000
来加载应用程序,因此我编辑了文件/etc/nginx/sites-available/default
以自动识别3000端口:
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
# Default server configuration
#
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;
server_name _;
location /server {
proxy_pass http://localhost:8000;
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;
}
location /phpmyadmin {
proxy_pass http://localhost:8080;
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;
}
location / {
proxy_pass http://localhost:3000;
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 snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
# fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
因此,尽管我可以不用端口进入我的IP地址xxx.xxx.xxx.xxx并查看我的应用程序,但是我无法与该应用程序的服务器部分进行通信。我尝试修改proxy_pass
中的location / {
以接受localhost:3000
和localhost:8000
(用逗号分隔),但是nginx测试失败。我去查询该问题的每个网站都建议为其创建一个特定的位置,但这显然不是答案。我很可能会提出错误的问题,因此,为了公开在/
位置使用的正确端口,我缺少什么?如果我将代码的这一部分手动更改为我的IP地址,则可以使用,但这真的有必要吗?请让我知道你们是否有答案。