Ubuntu 18上的nginx网站未在公共IP上加载 [英] nginx website on Ubuntu 18 not loading on public IP
问题描述
我正在尝试通过nginx在Amazon AWS EC2 Ubuntu 18.04上托管网站.我首先阅读了本教程一个>.我运行了 sudo apt update
和 sudo apt install nginx
.然后,我运行了 sudo ufw allow'Nginx HTTP'
.运行 sudo ufw status
会返回以下内容;
I am trying to host a website via nginx on Amazon AWS EC2 Ubuntu 18.04. I started by following this tutorial. I ran sudo apt update
and sudo apt install nginx
. Then, I ran sudo ufw allow 'Nginx HTTP'
. Running sudo ufw status
returned the following;
Status: active
To Action From
-- ------ ----
Nginx HTTP ALLOW Anywhere
OpenSSH ALLOW Anywhere
Nginx HTTP (v6) ALLOW Anywhere (v6)
OpenSSH (v6) ALLOW Anywhere (v6)
此后,我运行了 systemctl status nginx
并返回:
After that I ran systemctl status nginx
which returned:
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: en
Active: active (running) since Thu 2019-03-21 14:30:31 UTC; 1min 17s ago
Docs: man:nginx(8)
Process: 2657 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code
Process: 2644 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process
Main PID: 2661 (nginx)
Tasks: 2 (limit: 1152)
CGroup: /system.slice/nginx.service
├─2661 nginx: master process /usr/sbin/nginx -g daemon on; master_pro
└─2663 nginx: worker process
Mar 21 14:30:31 ip-172-31-29-16 systemd[1]: Starting A high performance web serv
Mar 21 14:30:31 ip-172-31-29-16 systemd[1]: nginx.service: Failed to parse PID f
Mar 21 14:30:31 ip-172-31-29-16 systemd[1]: Started A high performance web serve
lines 1-15/15 (END)...skipping...
● 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 Thu 2019-03-21 14:30:31 UTC; 1min 17s ago
Docs: man:nginx(8)
Process: 2657 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 2644 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 2661 (nginx)
Tasks: 2 (limit: 1152)
CGroup: /system.slice/nginx.service
├─2661 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─2663 nginx: worker process
Mar 21 14:30:31 ip-172-31-29-16 systemd[1]: Starting A high performance web server and a reverse proxy server...
Mar 21 14:30:31 ip-172-31-29-16 systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Mar 21 14:30:31 ip-172-31-29-16 systemd[1]: Started A high performance web server and a reverse proxy server.
然后,我尝试修复无法从文件/run/nginx.pid解析PID:无效参数
错误.我这样做是通过 mkdir/etc/systemd/system/nginx.service.d
,然后是 printf"[Service] \ nExecStartPost =/bin/sleep 0.1 \ n"
回来了
I then tried to fix the Failed to parse PID from file /run/nginx.pid: Invalid argument
error. I did that by doing mkdir /etc/systemd/system/nginx.service.d
, then printf "[Service]\nExecStartPost=/bin/sleep 0.1\n"
which returned
[服务]
ExecStartPost =/bin/sleep 0.1
[Service]
ExecStartPost=/bin/sleep 0.1
此后,我运行了 sudo nano/etc/systemd/system/nginx.service.d/override.conf
并将上面的引号插入其中并保存了.然后 sudo systemctl daemon-reload
和 sudo systemctl重新启动nginx
.在运行 systemctl status nginx
后返回以下代码:
After that I ran sudo nano /etc/systemd/system/nginx.service.d/override.conf
and inserted the above quote into there and saved it. Then sudo systemctl daemon-reload
and sudo systemctl restart nginx
. After that running systemctl status nginx
returned this:
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/nginx.service.d
└─override.conf
Active: active (running) since Thu 2019-03-21 14:54:44 UTC; 16s ago
Docs: man:nginx(8)
Process: 2941 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
Process: 2957 ExecStartPost=/bin/sleep 0.1 (code=exited, status=0/SUCCESS)
Process: 2955 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 2944 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 2956 (nginx)
Tasks: 2 (limit: 1152)
CGroup: /system.slice/nginx.service
├─2956 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─2962 nginx: worker process
Mar 21 14:54:44 ip-172-31-29-16 systemd[1]: Stopped A high performance web server and a reverse proxy server.
Mar 21 14:54:44 ip-172-31-29-16 systemd[1]: Starting A high performance web server and a reverse proxy server...
Mar 21 14:54:44 ip-172-31-29-16 systemd[1]: Started A high performance web server and a reverse proxy server.
我认为现在一切都应该正常工作,所以我运行了 curl localhost
并且返回了
I figured everything should be working now, so I ran curl localhost
and that returned
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
我相信我也应该能够从家用PC上访问它,所以我做了 curl ifconfig.me
来获取我的公共IP,然后我去了
I believe I should also be able to access this from my home PC, so I did curl ifconfig.me
to get my public IP and then I went to http://PUBLICIP, but it said This site can’t be reached.
有人可以帮我解决这个问题吗?
Can someone help me fix this please?
谢谢.
推荐答案
问题是我的AWS安全组,我添加了一个入站规则来接受所有TCP,现在它可以工作了.
Problem was my AWS security groups, I added an inbound rule to accept all TCP and now it works.
这篇关于Ubuntu 18上的nginx网站未在公共IP上加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!