Nginx安装配置-CentOS7
1、安装依赖
1、安装C++
//安装c++
yum install gcc-c++ -y
//查看版本
gcc -v
版本显示

2、安装ssl
yum install -y openssl openssl-devel
3、安装zlib
yum install -y zlib zlib-devel
//查看信息
cat /usr/lib64/pkgconfig/zlib.pc
版本显示

4、安装pcre
yum install -y pcre pcre-devel
//查看版本号
pcre-config --version
版本显示

2、下载并解压
【CSDN下载】
!!!我的nginx是放在export/install里面,这里可以进入你们所想要安装的地方。
官方网站下载 nginx:http://nginx.org/,进去随意点击一个,跳转到这个页面,选择1.18版本

cd export/install
//创建目录
mkdir -p export/install
tar -xvf nginx-1.18.0.tar.gz

3、安装nginx
//进入目录
cd nginx-1.18.0
//执行命令
./configure
//执行make命令
make
//执行make install命令
make install
4、查看目录
cd /
cd usr/local/nginx
ls

5、启动nginx
cd /usr/local/nginx/sbin
./nginx
只要显示nginx即可,后面的nginx.old不需要

6、关闭nginx
cd /usr/local/nginx/sbin
./nginx -s stop
7、重启nginx
cd /usr/local/nginx/sbin
./nginx -s reload
8、配置防火墙
设置80端口开放
firewall-cmd --zone=public --add-port=80/tcp --permanent

重启防火墙
firewall-cmd --reload

验证80端口是否开放成功
firewall-cmd --zone=public --query-port=80/tcp
测试链接
在浏览器输入你的LinuxIP地址,nginx默认端口是80,只需要输入IP地址即可!

9.nginx.conf配置
打开配置文件命令
vim /usr/local/nginx/conf/nginx.conf
编辑配置文件:
upstream jeecgxj { #server 127.0.0.1:2536; #server 127.0.0.1:2537; server 127.0.0.1:8080; } server { #xj合同模块 listen 3000;#默认端口是80,如果端口没被占用可以不用修改 server_name 39.105.36.80; #charset koi8-r; #access_log logs/host.access.log main; root E:/xj-contract/web/dist;#vue项目的打包后的dist location / { try_files $uri $uri/ @router;#需要指向下面的@router否则会出现vue的路由在nginx中刷新出现404 index index.html index.htm; } location /jeecg-boot { #try_files $uri $uri/ @router;#需要指向下面的@router否则会出现vue的路由在nginx中刷新出现404 #index index.html index.htm; proxy_pass http://jeecgxj; } #对应上面的@router,主要原因是路由的路径资源并不是一个真实的路径,所以无法找到具体的文件 #因此需要rewrite到index.html中,然后交给路由在处理请求资源 location @router { rewrite ^.*$ /index.html last; } #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; #} }
原文链接:https://blog.csdn.net/weixin_43451430/article/details/115558584

浙公网安备 33010602011771号