centos 安装nginx
1.安装方式一
1.yum install nginx
2.文件目录
config配置文件目录: /etc 文件夹下面
html文件目录: /usr/share/nginx/html 用于更新dist打包内容
3.启动nginx
4.卸载nginx
查看nginx是否运行
ps -ef| grep nginx
停止nginx /usr/sbin/niginx -s stop
5.删除yum remove nginx
6.删除nginx文件夹
查找文件:find / -name nginx
删除文件夹: rm -rf /usr/lib64/nginx /usr/share/nginx /var/log/nginx /var/lib/nginx
2.wget方式安装
1.安装依赖 yum -y install gcc gcc-c++ pcre pcre-devel gd-devel openssl openssl-devel zlib zlib-devel
安装gcc gcc-c++ pcre pcre-devel gd-devel(使nginx支持http rewrite模块)
安装openssl openssl-devel(使nginx支持ssl)
安装zlib zlib zlib-devel
2.下载nginx
wget -P /usr/local/nginx http://nginx.org/download/nginx-1.20.1.tar.gz
3.解压
tar -zxvf nginx-1.20.1.tar.gz
4.复制当前文件夹下内容到上级目录
cp -r * ../
5.复制子目录下的到当前目录
cp sub/* .
6.编译
./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/nginx.conf (可能会出现问题)
7.安装
make && make install
8.安装成功后启动
sudo /usr/local/nginx/sbin/nginx
sudo /usr/local/nginx/sbin/nginx -s stop
3.nginx配置
#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 8088;
server_name localhost;
# root /caiyun/caiyun/shifang_dapin;
#charset koi8-r;
#access_log logs/host.access.log main;
# location / {
# root html;
# index index.html index.htm;
# }
location / {
root /opt/homebrew/var/www;
try_files $uri $uri/ @router;
index index.html;
}
location @router {
rewrite ^.*$ /index.html last;
}
location /api {
proxy_pass https://fp.shifang.caiyunapi.com/api;
}
location /meteorologycdn/ {
proxy_pass https://meteorology.caiyuncdn.com/;
}
location /apicaiyun/ {
proxy_pass http://www.caiyunapi.com/;
}
location /caiyun/ {
proxy_pass https://api.caiyunapp.com/;
}
#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;
# }
#}
# include servers/*;
}