我正在尝试配置nginx以使用公共IP访问安装在EC2实例上的PWA应用程序,但是它不起作用(将IP地址加载为空)。
nginx.conf如下
user nginx;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
error_log /var/log/nginx/error.log;
events {
worker_connections 1024;
# 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; # 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/*;
server {
listen 80 default_server;
listen [::]:80 default_server;
client_max_body_size 50M;
server_name xx.xxx.xx.x; #EC2 public IPV4
root /usr/share/nginx/html;
return 301 https://$host$request_uri;
location /admin/api/users {
proxy_set_header X-uri $uri;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://localhost:9090/users;
}
location /admin/api/ {
proxy_set_header X-uri $uri;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://localhost:8080/;
}
location /admin/ {
proxy_set_header X-uri $uri;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://localhost:3030/;
}
location /api/ {
proxy_set_header X-uri $uri;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://localhost:8080/;
}
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://localhost:3000/;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
当我打开EC2公共IP地址时,它说“无法访问站点”。
ubuntu@ip-xxx-xx-x-xx:~$ sudo 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: active (running) since Fri 2019-10-04 13:20:07 UTC; 8min ago
Docs: man:nginx(8)
Process: 8704 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 8694 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 8708 (nginx)
Tasks: 2 (limit: 1152)
CGroup: /system.slice/nginx.service
├─8708 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─8711 nginx: worker process
Oct 04 13:20:07 ip-xxx-xx-x-xx systemd[1]: Starting A high performance web server and a reverse proxy server...
Oct 04 13:20:07 ip-xxx-xx-x-xx systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Oct 04 13:20:07 ip-xxx-xx-x-xx systemd[1]: Started A high performance web server and a reverse proxy server.
我正在学习nginx,请告知如何调试和解决此问题?