Linux 安装nginx教程
一、下载官网
下载放在 usr/local 下面 解压 tar -zxvf nginx-1.18.0.tar.gz
http://nginx.org/en/download.html
二、安装前需要安装其他依赖
1 |
|
三、安装 编译
进入解压后地 nginx目录 nginx-1.18.0
1执行
./configure --prefix=/usr/local/nginx
检查
2执行 # make && make install 编译 并且安装
报错情况1:修改文件 /usr/local/nginx-1.10.2/objs/Makefile
CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g
去掉 -Werror
CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused -g
报错情况2:
进入文件:/usr/local/nginx-1.10.2/src/os/unix/ngx_user.c
再次执行 :# make && make install
然后 usr/local 会多出一个nginx 文件夹
四、启动nginx并检查是否成功
1 进入 /usr/local/nginx/sbin
2 执行 ./nginx
五、防火墙开放端口 这个很重要
1 firewall-cmd --list-all 或者 firewall-cmd --zone=public --list-ports
2 添加端口 白名单 firewall-cmd --permanent --zone=public --add-port=8080/tcp
3 重启 防火墙 firewall-cmd --reload
这里有个参考地址:https://www.cnblogs.com/sucretan2010/p/10835175.html
六、访问地址 成功啦!
七、nginx 常用命令
必须进入安装的nginx/sbin/ 下面执行
-
./nginx 重启
-
./nginx -s stop 停止 或者 kill -9 进程号
-
./nginx -s reload 重新加载
-
./nginx -v 查看版本号
#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;
gzip on;
gzip_static on;
gzip_min_length 10k;
gzip_buffers 4 16k;
gzip_comp_level 6;
gzip_types *;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
server {
listen 80;
server_name IP;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /home/d2/dist/;
index index.html index.htm;
}
location /course/ {
alias /home/course/dist/;
index index.html index.htm;
}
location /d2/ {
alias /home/d2/dist/;
index index.html index.htm;
}
location /love/ {
alias /home/love/;
index index.html index.htm;
}
location /jwechat/ {
alias /home/d2/jwechat/;
index index.html index.htm;
}
location /dd/ {
alias /home/d2/dists2/;
index index.html index.htm;
}
location /static/ {
alias /home/static/;
index index.html index.htm;
}
location /api/ {
proxy_pass http://127.0.0.1:8082/api/;
break;
}
location /xxl-job-admin {
proxy_pass http://127.0.0.1:8081/xxl-job-admin;
break;
}
location /dapi/ {
proxy_pass http://127.0.0.1:8088/api/;
break;
}
}
# 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;
# }
#}
# 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;
# }
#}
}