原标题:如何使用浏览器访问linux本地文件
背景
因搜狗商城代码覆盖率报告均部署到服务器中,但是在服务器中无法使用浏览器查看html文件,因此使用Nginx配置一个静态web服务器,在本地通过浏览器访问服务器中的html文件。
一、安装编译工具及库文件
yum-y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
二、安装PCRE
PCRE 作用是让 Nginx 支持 Rewrite 功能。
1、下载 PCRE 安装包
cd /usr/local/src/
wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
2、解压安装包
tarzxvfpcre-8.35.tar.gz
3、进入安装包目录
cdpcre-8.35
4、编译安装
./configure
make&& makeinstall
5、查看pcre版本
pcre-config --version
三、安装Nginx
1、下载 Nginx
cd/usr/local/src/
wget http://nginx.org/download/nginx-1.9.9.tar.gz
2、解压安装包
tarzxvfnginx-1.9.9.tar.gz
3、进入安装包目录
cdnginx-1.9.9
4、编译安装
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
make
make install
5、查看nginx版本
/usr/local/nginx/sbin/nginx -v
到此,nginx安装完成。
四、Nginx配置
配置nginx.conf,将/usr/local/nginx/conf/nginx.conf替换为以下内容:
userroot root;
worker_processes2; #设置值和CPU核心数一致
error_log/usr/local/webserver/nginx/logs/nginx_error.log crit; #日志位置和日志级别
pid/usr/local/webserver/nginx/nginx.pid;
#Specifies the value for maximum file deors that can be opened by this process.
worker_rlimit_nofile65535;
events
{
useepoll;
worker_connections65535;
}
http
{
includemime.types;
default_typeapplication/octet-stream;
log_formatmain '$remote_addr - $remote_user [$time_local] "$request" '
'$status$body_bytes_sent "$http_referer" '
'"$http_user_agent"$http_x_forwarded_for';
#charset gb2312;
server_names_hash_bucket_size128;
client_header_buffer_size32k;
large_client_header_buffers4 32k;
client_max_body_size8m;
sendfileon;
tcp_nopushon;
keepalive_timeout60;
tcp_nodelayon;
fastcgi_connect_timeout300;
fastcgi_send_timeout300;
fastcgi_read_timeout300;
fastcgi_buffer_size64k;
fastcgi_buffers4 64k;
fastcgi_busy_buffers_size128k;
fastcgi_temp_file_write_size128k;
gzipon;
gzip_min_length1k;
gzip_buffers4 16k;
gzip_http_version1.0;
gzip_comp_level2;
gzip_typestext/plain application/x-java text/css application/xml;
gzip_varyon;
#limit_zone crawler $binary_remote_addr 10m;
#下面是server虚拟主机的配置
server
{
listen80;#监听端口
server_namelocalhost;#域名
indexindex.html index.htm index.php;
rootroot /usr/local/jacoco/report;;#站点目录
location~ .*.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
includefastcgi.conf;
}
location~ .*.(gif|jpg|jpeg|png|bmp|swf|ico)$
{
expires30d;
# access_log off;
}
location~ .*.(js|css)?$
{
expires15d;
# access_log off;
}
access_logoff;
}
}
检查配置文件nginx.conf的正确性命令:
/usr/local/nginx/sbin/nginx -t
启动 Nginx,启动命令如下:
/usr/local/nginx/sbin/nginx
访问站点:从浏览器访问我们配置的站点ip,可以查看啦,因为80端口被占用,所以nginx端口更改为8688啦。返回搜狐,查看更多
责任编辑: