准备文件
https://www.openssl.org/source/openssl-1.1.0e.tar.gz
https://ftp.pcre.org/pub/pcre/pcre-8.37.tar.gz
http://www.zlib.net/zlib-1.2.11.tar.gz
http://nginx.org/download/nginx-1.13.7.tar.gz
一、准备环境
1.检查gcc,g++
如果没有,参考这篇centOS7离线安装redis
2.安装其他环境包
上传一下安装包
路径为/usr/local/software/nginx-packages
(1)解压并安装pcre
tar -zxvf pcre-8.37.tar.gz
cd pcre-8.37/
./configure
make && make install
(2)解压并安装zlib
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11/
./configure
make && make install
(3)解压并安装openssl
tar -zxvf openssl-1.1.0e.tar.gz
cd openssl-1.1.0e/
./config
make && make install
二、nginx的安装与配置
1.安装nginx
(1)解压nginx压缩包
[root@ohMyGod nginx-packages]# tar -zxvf nginx-1.13.7.tar.gz
#解压后目录结构
[root@ohMyGod nginx-packages]# ls
nginx-1.13.7 openssl-1.1.0e pcre-8.37 zlib-1.2.11
nginx-1.13.7.tar.gz openssl-1.1.0e.tar.gz pcre-8.37.tar.gz zlib-1.2.11.tar.gz
(2)编译与安装
[root@ohMyGod nginx-packages]# cd nginx-1.13.7/
[root@ohMyGod nginx-1.13.7]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre=../pcre-8.37 --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-1.1.0e
[root@ohMyGod nginx-1.13.7]# make && make install
(3)启动与停止
[root@ohMyGod nginx-1.13.7]# cd /usr/local/nginx/sbin
[root@ohMyGod sbin]# ./nginx
(4)开机启动
[root@ohMyGod local]# cd /lib/systemd/system/
[root@ohMyGod system]# vim nginx.service
编辑如下内容,并保存
[Unit]
Description=nginx service
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
加入开机启动
[root@ohMyGod system]# systemctl enable nginx
(5)如果防火墙开着
#查看端口
firewall-cmd --zone=public --list-ports
#开放端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
#重启防火墙
systemctl restart firewalld
2.配置nginx
普通配置参考之前的系列
https://www.jianshu.com/p/97bb27c1e0c4
增加nginx虚拟主机配置文件(conf.d)如下:
(1)修改位置
在原来文件/usr/local/nginx/conf/nginx.conf 的http 块下加一句
include /usr/local/nginx/conf.d/*.conf;
(2)完整/usr/local/nginx/conf/nginx.conf配置文件
#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;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# 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;
# }
#}
include /usr/local/nginx/conf.d/*.conf;
}
(3)虚拟主机的配置文件
虚拟主机的配置文件写在/etc/nginx/conf.d/目录下了,如123.com.conf
server {
listen 80;
server_name 123.com;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
root /var/nginx/html/123.com;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root /var/nginx/html/123.com;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
参考自
https://blog.csdn.net/achi010/article/details/106392040/
https://www.cnblogs.com/jepson6669/p/9131217.html
https://www.cnblogs.com/fps2tao/p/9958009.html