Nginx是一个免费的,开源的,高性能的HTTP服务器和反向代理,以及IMAP / POP3代理服务器。
Nginx以其高性能,稳定性,丰富的功能集,简单的配置和低资源消耗而闻名。
Nginx使用更加可扩展的事件驱动(异步)架构,此体系结构在负载下使用较小但更重要的可预测内存量。即便您不但愿同时处理数千个请求,您仍然能够从Nginx的高性能和小内存占用中受益。
Nginx能够向各个方向扩展:从最小的VPS一直到大型服务器集群。html
sudo yum install epel-release
sudo yum install nginx
Nginx 不会本身启动,启动命令:node
sudo systemctl start nginx
若是外部浏览器输入该机IP仍是访问不了,说明有防火墙正在运行,关闭HTTP 和 HTTPS的防火墙:python
sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --reload
外部浏览器访问成功,说明Nginx安装成功。
linux
最后,由于Nginx默认是不主动开启的,为了可以在系统启动就开启Nginx:nginx
sudo systemctl enable nginx
vi /etc/nginx/nginx.conf
nginx.conf文件http配置内容,而且i
进去注释掉http配置下server的默认配置内容Esc
+:wq
保存后退出。shell
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 /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; #【解释】nginx会加载 /etc/nginx/conf.d文件夹下全部的conf文件的配置 # server { # listen 80 default_server; # listen [::]:80 default_server; # server_name _; # root /usr/share/nginx/html; # # # Load configuration files for the default server block. # include /etc/nginx/default.d/*.conf; # # location / { # } # # error_page 404 /404.html; # location = /40x.html { # } # # error_page 500 502 503 504 /50x.html; # location = /50x.html { # } # }
根据nginx配置文件有提示,在/etc/nginx/conf.d文件夹下为hellocore项目新建一个netcore.conf文件,文件配置以下浏览器
server { listen 80; location / { proxy_pass http://localhost:5000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } }
重启nginx服务器
nginx -s reload # systemctl restart nginx
外部访问有可能会报502错误架构
缘由:
SELinux配置问题
解决:
方法1.关闭SELinux
输入:sestatus
,若是SELinux status: enabled
,表示开启,输入vi /etc/selinux/config
修改配置:SELINUX=disabled
。
方法2.将nginx添加至SELinux的白名单app
逐行执行以下命令:
yum install policycoreutils-python cat /var/log/audit/audit.log | grep nginx | grep denied | audit2allow -M mynginx semodule -i mynginx.pp