centOS安装nginx
1.查看系统是否安装gcc,如果没有的话执行下面步骤
查看gcc版本
gcc -v
存在跳过,不存在安装
yum -y install gcc
2.pcre、pcre-devel安装
yum install -y pcre pcre-devel
3.zlib安装
yum install -y zlib zlib-devel
4.openssl安装
yum install -y openssl openssl-devel
5.nginx安装,以下方式二选一
①:
wget https://nginx.org/download/nginx-1.18.0.tar.gz
②:或者去官网下载
https://nginx.org/en/download.html
6.解压tar.gz包
tar -zxvf nginx-1.18.0.tar.gz
7.使用默认配置
./configure
8.编译安装
①:编译
make
②:安装
make install
③:查看安装路径
whereis nginx
9.启动
①:进入目录
cd /usr/local/nginx/sbin/
②:启动nginx
./nginx
③:相关命令
// nginx启动命令
./nginx
// nginx停止命令
./nginx -s stop
// nginx重启命令
./nginx -s reload
//查看进程
ps aux|grep nginx
指定配置文件启动
./sbin/nginx -s reload -c /你的目录/nginx.conf
10.开启自启动
vi /etc/rc.local
增加一行
/usr/local/nginx/sbin/nginx
设置执行权限
chmod 755 /etc/rc.local
拓展:将nginx作为系统服务
sudo systemctl enable nginx
sudo systemctl start nginx
10.设置域名
贴配置
#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 你的域名;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
try_files $uri $uri/ /index.html?$query_string;
root /usr/local/project/client/dist/;
index index.html index.htm;
}
location /prod-api/ {
rewrite ^/prod-api/(.*)$ /$1 break;
proxy_pass http://127.0.0.1:8080;
}
#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;
# }
#}
}