Nginx安装与使用
window or linux Nginx部署项目
window
一、下载Nginx,下载好解压至桌面,或者D盘,C盘实际看自己喜好
下载双击就可以看到站点搭建好了
二、部署 在\nginx-1.18.0\html\
目录下新建项目文件夹xiaohong
,注:我这里取名xiaohong 也可以去其他名字
打开xiaohong
这个文件夹把前端打包好的文件(dist)全部放到此目录下
三、配置\nginx-1.18.0\conf\目录下的nginx.conf ,location / 下root
修改为 html/xiaohong
重启就可以访问了
./nginx.exe -s reload
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/xiaohong; #文件目录 也可以二级目录访问 需要vue时设置基础打包路径
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 /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;
# }
#}
}
地址栏:http://127.0.0.1
linux
一、下载安装 Nginx、解压、编译安装
// https 依赖
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
wget http://nginx.org/download/nginx-1.17.10.tar.gz
tar -xvzf nginx-1.17.10.tar.gz
cd nginx-1.17.10
./configure --prefix=/usr/local/nginx --with-http_addition_module --with-http_flv_module --with-http_gzip_static_module --with-http_realip_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_dav_module --with-http_v2_module
make && make install
先查看安装路径然后启动 启动Ngnix ,每个服务器安装位置可能有差异安装自行查看
whereis nginx #查看安装路径
cd /usr/local/nginx/sbin
./nginx -t #验证nginx配置文件
./nginx #启动
./nginx -s stop #关闭
./nginx -s reload #重启
**注: nginx.conf 文件配置和window一致!!!
版权声明:
本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自
小红!
喜欢就支持一下吧