Nginx安装需要gcc-c++编译环境,另外还需要安装Nginx依赖包。
下载gcc-c++
打开gcc-c++ rpm下载地址:https://pkgs.org/download/gcc-c++
选择对应的Linux CentOS版本进行下载:
最新的选择CentOS7,为了保险起见,我们选择最多的rpm支持版本
将这些rpm逐个下载即可。下载时需要进入到每一个页面对应的Download:
注:为了不出错,将以上列举的*.rpm都下载。
安装gcc-c++
可以只安装一个rpm:
rpm -ivh gcc-c++-4.4.7-4.el6.x86_64.rpm #名字自行修改
当然也可以将所有下载的rpm文件放入/home/gcc-c++路径下,安装一个路径下所有rpm包:
#rpm -Uvh *.rpm --nodeps --force #安装路径下所有rpm
安装软件示例:
# rpm -hvi dejagnu-1.4.2-10.noarch.rpm
警告:dejagnu-1.4.2-10.noarch.rpm: V3 DSA 签名:NOKEY, key ID db42a60e准备... ########################################### [100%]
显示软件安装信息
# rpm -qi dejagnu-1.4.2-10.noarch.rpm
卸载软件示例:
pm –e [your package]
注意:是安装后的包,可能与原包名称有差异。
安装zlib-devel
下载方式同gcc-c++方式,单个rpm安装:
rpm -ivh zlib-devel-1.2.3-29.el6.x86_64.rpm
注意:系统版本要对应,如依然报错请安装openssl和 openssl-devel。
Nginx上传解压编译
上传:
可以通过TFP上传文件到服务器/home路径下。
解压:
tar -zxvf nginx-1.17.2.tar.gz
编译:
进入路径/home/nginx/nginx-1.17.2,
依次执行如下命令:
./configure --prefix=/home/nginx/nginx
make
make install
如此即可安装上Nginx,此时会为我们生成/home/nginx/nginx
注:可启动文件在/home/nginx/nginx/sbin下。
Nginx启动、重载和停止
启动:/home/nginx/nginx/sbin/nginx
重载:/home/nginx/nginx/sbin/nginx -s reload
停止:/home/nginx/nginx/sbin/nginx -s stop
注意:/home/nginx/nginx/sbin/nginx -s start启动不了Nginx。
Nginx本机代理配置
修改/home/nginx/nginx/conf/nginx.conf,Nginx代理监听8090端口。
#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 8090;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
# 代理同步服务服务端
location ^~ /datasynchronize-server/ {
proxy_pass http://10.0.70.106:8090/datasynchronize-server/;
# 以下配置支持ws服务
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
#代理本机同步服务客户端
location ^~ /datasynchronize/ {
proxy_pass http://10.0.70.103:8080/datasynchronize/;
# 以下配置支持ws服务
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
# 图片上传路径-Nginx代理后台管理系统访问图片
location ^~ /upload/ {
alias /usr/Tomcat/apache-tomcat-8.5.43-8082/webapps/ROOT/upload/;
}
location ^~ /server/upload/ {
proxy_pass http://localhost:8082/upload/;
}
#默认代理本机啄木鸟服务
location / {
root html;
index index.html index.htm;
proxy_pass http://10.0.70.103:8082;
# 以下配置支持ws服务
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
#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 /scripts$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;
# }
#}
}