NginxNginx的学习(2.Nginx的安装,Linux安装和Windows安装)
Posted 还是那个同伟伟
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NginxNginx的学习(2.Nginx的安装,Linux安装和Windows安装)相关的知识,希望对你有一定的参考价值。
1.nginx下载
Nginx官网下载地址 http://nginx.org/en/download.html
1.1 windows安装
windows安装很简单,直接下载windows的版本,注意不要放到包含中文的路径下面
打开下载路径的cmd的窗口,输入 nginx.exe回车即可,
浏览器输入 http://localhost:80 有如下页面即启动成功
1.2 Linux安装
- 可以使用上面的nginx官网下载,文件上传解压
- 也可以使用命令
yum install nginx
- 这里记录一个小问题,阿里云服务配置的80端口安全组,却访问不了? 解决方法如下:
# 查看防火墙端口
firewall-cmd --list-all
# 加入80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
# 重启生效
firewall-cmd --reload
- 启动nginx
systemctl start nginx
再次访问就可以了
yum方式安装的默认地址和配置的默认地址
/etc/nginx/nginx.conf //yum方式安装后默认配置文件的路径
/usr/share/nginx/html //nginx网站默认存放目录
/usr/share/nginx/html/index.html //网站默认主页路径
nginx学习1:Linux安装nginx
nginx学习1:Linux安装nginx
nginx安装环境准备
1-安装pcre、openssl、zlib
2-安装指令:yum -y install gcc zlib zlib-devel pcre-devel openssl openssldevel
Installed: pcre-devel.x86_64 0:8.32-17.el7 zlib-devel.x86_64 0:1.2.7-18.el7 Updated: openssl.x86_64 1:1.0.2k-19.el7 zlib.x86_64 0:1.2.7-18.el7 Dependency Updated: openssl-libs.x86_64 1:1.0.2k-19.el7 Complete!
下载并安装nginx
...........
Configuration summary + using system PCRE library + OpenSSL library is not used + using system zlib library nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/local/nginx/sbin/nginx" nginx modules path: "/usr/local/nginx/modules" nginx configuration prefix: "/usr/local/nginx/conf" nginx configuration file: "/usr/local/nginx/conf/nginx.conf" nginx pid file: "/usr/local/nginx/logs/nginx.pid" nginx error log file: "/usr/local/nginx/logs/error.log" nginx http access log file: "/usr/local/nginx/logs/access.log" nginx http client request body temporary files: "client_body_temp" nginx http proxy temporary files: "proxy_temp" nginx http fastcgi temporary files: "fastcgi_temp" nginx http uwsgi temporary files: "uwsgi_temp" nginx http scgi temporary files: "scgi_temp"
4-编译并安装nginx:make && make install
............ test -d \'/usr/local/nginx/logs\' \\ || mkdir -p \'/usr/local/nginx/logs\' make[1]: Leaving directory `/opt/nginx-1.12.2\'
#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; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main;
6-启动ngnix(执行 /usr/local/nginx/sbin/下的nginx脚本):先cd /usr/local/nginx/sbin/;再./nginx
8-查看nginx状态:lsof -i:8081
[root@VM_0_4_centos sbin]# lsof -i:8081 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx 16148 root 6u IPv4 98149743 0t0 TCP *:tproxy (LISTEN) nginx 16149 nobody 6u IPv4 98149743 0t0 TCP *:tproxy (LISTEN)
检查防火墙是否允许对应的端口号开放
如下异常:
FirewallD is not running
2-查看防火墙状态:systemctl status firewalld
防火墙dead ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:firewalld(1)
3-启动防火墙:systemctl start firewalld (重新查看防火墙状态如下)
防火墙running ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: active (running) since Wed 2020-01-29 15:55:58 CST; 1min 54s ago Docs: man:firewalld(1) Main PID: 10829 (firewalld) Tasks: 2 Memory: 27.1M CGroup: /system.slice/firewalld.service └─10829 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
4-继续查看防火墙允许的端口号:firewall-cmd --list-all
无端口号开放 public target: default icmp-block-inversion: no interfaces: sources: services: ssh dhcpv6-client ports: protocols: masquerade: no forward-ports: source-ports: icmp-blocks:
5-开放8081端口号:先firewall-cmd --add-port=8081/tcp --permanent;再firewall-cmd --reload
添加端口号 [root@VM_0_4_centos sbin]# firewall-cmd --add-port=8081/tcp --permanent success 重新加载防火墙 [root@VM_0_4_centos sbin]# firewall-cmd --reload success 查看开放端口 [root@VM_0_4_centos sbin]# firewall-cmd --list-all public target: default icmp-block-inversion: no interfaces: sources: services: ssh dhcpv6-client ports: 8081/tcp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:
浏览器访问nginx
以上是关于NginxNginx的学习(2.Nginx的安装,Linux安装和Windows安装)的主要内容,如果未能解决你的问题,请参考以下文章