centos6.5服务器安装Nginx设置服务和开机自启的方法

本篇文章主要介绍了centos6.5服务器安装Nginx设置服务和开机自启的方法,具有一定的参考价值,有兴趣的小伙伴可以了解一下
本文介绍了centos6.5服务器安装Nginx设置服务和开机自启的方法,分享给大家,也给自己留个笔记

1、安装Nginx及其依赖

首先是老套路,使用ssh链接服务器,还记得以前的代码吗?

ssh -t 用户名@服务器IP或者域名 -p 22 ssh -t [email protected] -p 22
在终端中输入上面命令按下回车,要求我们输入密码,这个密码是不可见的,所以一定要输入正确。

链接到服务器后,我们切换到常用的安装路径,当然我服务器上面的安装路径是/usr/src,接着开始在终端操作:

cd /usr/src mkdir Nginx yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz tar -zxvf pcre-8.40.tar.gz cd pcre-8.40 ./configure make make install cd .. wget http://zlib.net/zlib-1.2.11.tar.gz tar -zxvf zlib-1.2.11.tar.gz cd zlib-1.2.11 ./configuremakemake install cd .. wget http://www.openssl.org/source/openssl-fips-2.0.14.tar.gz tar -zxvf openssl-fips-2.0.14.tar.gz yum -y install openssl openssl-devel wget http://nginx.org/download/nginx-1.4.2.tar.gztar -zxvf nginx-1.4.2.tar.gzcd nginx-1.4.2 ./configure --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcremakemake install

到这里来讲,我们的nginx安装完成了,但是我们还需要做更多的事情,那就是配置服务器,添加ssl访问,设置服务和开机启动

2、配置服务器

互联网上关于服务器设置的很多,但是准确阐述的却不是那么多,而我刚好是在看了他们的东西后就呵呵了。正确的配置方法如下:

cd /opt/nginx/conf vi nginx.conf

我的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 - r e m o t e u s e r [ remote_user [ time_local] “KaTeX parse error: Expected 'EOF', got '#' at position 12: request" ' #̲ 'status b o d y b y t e s s e n t " body_bytes_sent " http_referer” ’ # ‘“ h t t p u s e r a g e n t " " 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; index index.html index.htm; # proxy_pass http://localhost; # proxy_set_header Host $host; # proxy_set_header X-Real-IP $remote_addr; # proxy_set_header X-Forwarded-For KaTeX parse error: Double subscript at position 12: proxy_add_x_̲forwarded_for; … { # 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访问的,这里必须设置才能正确时https # HTTPS server # server { listen 443; server_name localhost acheng1314.cn www.acheng1314.cn; ssl on; # 这里是你申请的签名,扔到conf下面的cert目录中 ssl_certificate cert/214217283570796.pem; ssl_certificate_key cert/214217283570796.key; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_prefer_server_ciphers on; location / { # root html; # index index.html index.htm; proxy_pass http://localhost; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }}# 这里是设置域名跳转的,转发这些域名到本机的8080端口,server { listen 80; server_name *.acheng1314.cn acheng1314.cn; location / { proxy_pass http://localhost:8080/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } }

猜你喜欢

转载自blog.csdn.net/weixin_44400506/article/details/88032117
今日推荐