繁体   English   中英

如何将 nginx 与 adonis 一起使用?

[英]How can I use nginx with adonis?

我正在尝试部署一个 api adonis,我正在尝试使用 nginx 来启用对我的 http 请求的外部访问。

我安装 nginx 并进入 ssh 我去:

cd /etc/nginx
vi nginx.conf

所以,我把这个代码:

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

    server {
        listen 80;

        server_name knowhowexpressapp.com ;

        location / {
            proxy_pass http://localhost:3333;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_cache_bypass $http_upgrade;
        }
    }


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

在服务器名称中,我输入了域; 在端口中我放置了 3333 因为是我放置在 .env 中的端口;

我启动nginx:

cd /usr/bin/etc/nginx
nginx

检查 nginx 是否正在运行:

[root@knowhowexpressapp etc]# ps aux | grep nginx
root      14143  0.0  0.0  55320  1028 ?        Ss   11:41   0:00 nginx: master process nginx
nginx     14144  0.0  0.0  55708  1936 ?        S    11:41   0:00 nginx: worker process
root      14188  0.0  0.0 112712   964 pts/2    S+   11:42   0:00 grep --color=auto nginx

我的 .env 档案:

HOST=ip from my server
PORT=3333
NODE_ENV=production
APP_NAME=AdonisJs
APP_URL=http://${HOST}:${PORT}
CACHE_VIEWS=false
APP_KEY=GPhustNKtbIlrxawTZa6xQTIkHcjBXFr
DB_CONNECTION=pg
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=xxxx
DB_DATABASE=xxx
HASH_DRIVER=bcrypt

所以,我检查 pm2 并且我的服务器正在运行:

⇆ PM2+ activated 
┌─────┬───────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name      │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼───────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0   │ server    │ default     │ 4.1.0   │ fork    │ 12586    │ 16m    │ 34   │ online    │ 0%       │ 41.0mb   │ root     │ disabled │

但是当我尝试访问我的 api 时,我得到:

无法得到任何响应 连接到https://knowhowexpressapp.com/login 时出错。

我的服务器是centos 7

我的 api 仅在我输入http://ipfrommyserver时才运行,但是当我尝试访问域时,我收到错误消息。

嗯...我看到了,正如同伴所说,似乎缺少将DNS指向API的东西...更好地使用IP,它更容易...

它有 DNS 传播时间......并加速......清除浏览器的缓存很好......在匿名浏览器中尝试......另一个浏览器......另一台PC......甚至在巴西的情况下。 .. 关闭调制解调器... 更改 IP 并更新调制解调器的 DNS。

还有 CRTL + Shift + R

关于登录...

当您访问: http : //knowhowexpressapp.com/login

 HttpException: E_ROUTE_NOT_FOUND: route not found GET / login

当您访问: http : //knowhowexpressapp.com/#/login

你可以看到登录页面...

即使放入https ...

顺便说一下,看看你是否正确发布了 SSL。

要了解门,我推荐 UFW,因为它最小化和更新更实用。

发送消息!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM