In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the centos6.5 server installation Nginx setting service and boot self-boot example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
1. Install Nginx and its dependencies
The first is the old routine, using ssh to link to the server, remember the previous code?
Ssh-t user name @ server IP or domain name-p 22ssh-t root@acheng1314.cn-p 22
Enter the above command in the terminal and press enter, asking us to enter the password, which is invisible, so be sure to enter it correctly.
After linking to the server, we switch to the usual installation path. Of course, the installation path on my server is / usr/src, and then we start to operate on the terminal:
Cd / usr/srcmkdir Nginxyum-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.gztar-zxvf pcre-8.40.tar.gzcd pcre-8.40./configuremakemake installcd.. wget http://zlib.net/zlib-1.2.11.tar.gztar-zxvf zlib-1.2.11.tar.gzcd zlib-1.2.11./configuremakemake installcd .. wget http://www.openssl.org/source/openssl-fips-2.0.14.tar.gztar-zxvf openssl-fips-2.0.14.tar.gzyum-y install openssl openssl-develwget 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
At this point, our nginx installation is complete, but we still need to do more, that is, configure the server, add ssl access, set up the service, and boot
2. Configure the server
There are a lot of server settings on the Internet, but there is not so much accurate explanation, and I happen to be after reading their things. The correct configuration method is as follows:
Cd / opt/nginx/confvi nginx.conf
My nginx.conf is as follows:
# user nobody;worker_processes 1 the errorless 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 # Note here is something related to setting up this machine. It is recommended not to change 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 $proxy_add_x_forwarded_for;} # error_page 404 / 404.html; # redirect server error pages to the static page / 50x.html # error_page 500502503504 / 50x.html; location = / 50x.html {root html } # proxy the PHP scripts to Apache listening on 127.0.0.1 location 80 # location ~. Php$ {# proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1 proxy_pass 9000 # # location ~. Php$ {# root html; # fastcgi_pass 127.0.1 location 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; #} #} # here the native https access is set, and the https # HTTPS server # server {listen 443; server_name localhost acheng1314.cn www.acheng1314.cn; ssl on must be set to be correct. # here is the signature you applied for. Throw it into the cert directory under conf: ssl_certificate cert/214217283570796.pem; ssl_certificate_key cert/214217283570796.key; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHEMUR RSAMUA AES128Mae GCMMurSHA256v ECDHEV ECDH Vista ACDH laxa null LMU Md 5D Md 5V ADH RC4 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;}} # here is to set the domain name jump to forward these domain names to port 8080 of this machine, 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;}
In fact, when writing this, we must pay attention to that no matter what application port can not conflict! For example, my nginx is bound to port 80, if tomcat sets port 80 again, then my settings will fail to forward even if bound to localhost! After all, the network port can only be occupied by one application.
/ opt/nginx/sbin/nginx-t/opt/nginx/sbin/nginx/opt/nginx/sbin/nginx-t/sbin/iptables-I INPUT-p tcp-- dport 443-j ACCEPT/etc/rc.d/init.d/iptables save/etc/init.d/iptables status
At this point, we can test the server. Normally, my current server is fully supported by http and https.
3. Set up service and self-startup
In fact, there is basically nothing to pay attention to here, as long as the nginx path is set correctly.
#! / bin/sh# Name:nginx4comex# nginx-this script starts and stops the nginx daemon## description: Nginx is an HTTP (S) server, HTTP (S) reverse\ # proxy and IMAP/POP3 proxy server# processname: nginx# config: / opt/nginx/conf/nginx.conf# pidfile: / comexHome/nginx/nginx.pid## Created By http://comexchan.cnblogs.com/# Source function library.. / etc/rc.d/init.d/functions# Source networking configuration.. / etc/sysconfig/network# Check that networking is up. ["$NETWORKING" = "no"] & & exit 0NGINXroomDAEMONAMOPATH = "/ opt/nginx/sbin/nginx" NGINX_CONF_FILE= "/ opt/nginx/conf/nginx.conf" NGINX_LOCK_FILE= "/ var/lock/subsys/nginx4comex" prog=$ (basename $NGINX_DAEMON_PATH) start () {[- x $NGINX_DAEMON_PATH] | exit 5 [- f $NGINX_CONF_FILE] | | exit 6 echo-n $"Starting $prog:" daemon $NGINX_DAEMON_PATH-c $NGINX_CONF_FILE retval=$? Echo [$retval-eq 0] & & touch $NGINX_LOCK_FILE return $retval} stop () {echo-n $"Stopping $prog:" killproc $prog-QUIT retval=$? Echo [$retval-eq 0] & & rm-f $NGINX_LOCK_FILE return $retval} restart () {configtest | | return $? Stop start} reload () {configtest | | return $? Echo-n $"Reloading $prog:" killproc $NGINX_DAEMON_PATH-HUP RETVAL=$? Echo} force_reload () {restart} configtest () {$NGINX_DAEMON_PATH-t-c $NGINX_CONF_FILE} rh_status () {status $prog} rh_status_q () {rh_status > / dev/null 2 > & 1} case "$1" in start) rh_status_q & & exit 0 $1; stop) rh_status_q | | exit 0 $1;; restart | configtest) $1 Reload) rh_status_q | | exit 7 $1;; force-reload) force_reload;; status) rh_status;; condrestart | try-restart) rh_status_q | | exit 0;; *) echo $"Usage: $0 {start | stop | status | restart | condrestart | try-restart | reload | force-reload | configtest}" exit 2esac
The above code is the code used to create the service and save it in the nginx4comex file (which I still have in the / opt/nginx directory, also written in vim). Note that the following code corresponds to your configuration.
NGINX_DAEMON_PATH= "/ opt/nginx/sbin/nginx" NGINX_CONF_FILE= "/ opt/nginx/conf/nginx.conf"
Then we continue with the terminal command operation.
Chmod uplix nginx4comexcp nginx4comex / etc/init.dservice nginx4comex statusvim / etc/rc.local/etc/init.d/nginx4comex startreboot
Finally, we have set up the nginx proxy tomcat and the corresponding server program to start itself.
Be careful! Nginx4comex can not be chkconfig, the specific reason I do not know, but the original author's article did use the method of chkconfig to add startup, interested in linux can give it a try.
Thank you for reading this article carefully. I hope the article "centos6.5 server installation Nginx setup service and boot self-boot example analysis" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.